访问 FormView 实例时出现 ArgumentNullException

发布于 2024-10-10 08:47:56 字数 3324 浏览 7 评论 0原文

背景:

我有一个 ASP.NET 页面,其中有许多用户控件。有 2 个值得关注的用户控件。我需要显示其中之一或都不显示,具体取决于之前选择的记录。

在用户控件中,我需要设置 FormView 中某些控件的属性。因此,在我的用户控件代码隐藏中,我有许多属性,它们看起来像这样:

Private ReadOnly Property phSectionReports() As PlaceHolder
    Get
        Return fvConfirmationReport.FindControl("phSectionReports")
    End Get
End Property

问题:

我遇到了此属性的问题。有时它返回 Nothing/Null,有时它抛出 NullArgumentException 并显示消息“值不能为 null。参数名称:容器”。异常来自尝试引用 fvConfirmationReport 变量。 fvConfirmationReport 是页面本身中我的 FormView 的 ID。

所以我真的在寻找要寻找的东西,如果有任何想法什么样的条件(例如页面循环中的阶段等)可能会导致这种情况?

示例堆栈跟踪包含在下面。
ASP.NET 3.5 SP1、VB.NET

谢谢,

StackTrace:

   at System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName)
   at System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding)
   at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)
   at System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data)
   at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)
   at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
   at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
   at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
   at System.Web.UI.WebControls.GridView.DataBind()
   at System.Web.UI.Control.DataBindChildren()
   at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
   ...snip...
   at System.Web.UI.Control.DataBind()
   at System.Web.UI.Control.DataBindChildren()
   at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
   at System.Web.UI.WebControls.FormView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding)
   at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)
   at System.Web.UI.WebControls.FormView.PerformDataBinding(IEnumerable data)
   at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)
   at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
   at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
   at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
   at System.Web.UI.WebControls.FormView.DataBind()
   at System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound()
   at System.Web.UI.WebControls.FormView.EnsureDataBound()
   at System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls()
   at System.Web.UI.Control.EnsureChildControls()
   at System.Web.UI.Control.FindControl(String id, Int32 pathOffset)
   at System.Web.UI.Control.FindControl(String id)
   at App_UserControls_xxx_ucConfirmationForm.get_phSectionReports() in ucConfirmationForm.ascx.vb:line 343
   at App_UserControls_xxx_ucConfirmationForm.Page_Load(Object sender, EventArgs e) in ucConfirmationForm.ascx.vb:line 412
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   ...snip...
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Background:

I have an ASP.NET page which has a numebr of user controls within it. There are 2 user controls which are of interest. I need to display either one of them or neither of them, depending on the record selected previously.

In the user controls I need to set properties of some controls which are in a FormView. So in my user control code-behind I have a number of properties which look something like this:

Private ReadOnly Property phSectionReports() As PlaceHolder
    Get
        Return fvConfirmationReport.FindControl("phSectionReports")
    End Get
End Property

The problem:

I am having problems with this Property. Sometimes it is returning Nothing/Null and sometimes it is throwing a NullArgumentException with the message "Value cannot be null. Parameter name: container". The exception is coming from trying to reference the fvConfirmationReport variable. fvConfirmationReport is the ID of my FormView in the page itself.

So I am really after things to look for and if any ideas what sort of conditions (e.g stage in page cycle, etc.) might lead to this?

An example stack trace is included below.
ASP.NET 3.5 SP1, VB.NET

Thanks,

StackTrace:

   at System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName)
   at System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding)
   at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)
   at System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data)
   at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)
   at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
   at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
   at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
   at System.Web.UI.WebControls.GridView.DataBind()
   at System.Web.UI.Control.DataBindChildren()
   at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
   ...snip...
   at System.Web.UI.Control.DataBind()
   at System.Web.UI.Control.DataBindChildren()
   at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
   at System.Web.UI.WebControls.FormView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding)
   at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)
   at System.Web.UI.WebControls.FormView.PerformDataBinding(IEnumerable data)
   at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)
   at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
   at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
   at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
   at System.Web.UI.WebControls.FormView.DataBind()
   at System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound()
   at System.Web.UI.WebControls.FormView.EnsureDataBound()
   at System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls()
   at System.Web.UI.Control.EnsureChildControls()
   at System.Web.UI.Control.FindControl(String id, Int32 pathOffset)
   at System.Web.UI.Control.FindControl(String id)
   at App_UserControls_xxx_ucConfirmationForm.get_phSectionReports() in ucConfirmationForm.ascx.vb:line 343
   at App_UserControls_xxx_ucConfirmationForm.Page_Load(Object sender, EventArgs e) in ucConfirmationForm.ascx.vb:line 412
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   ...snip...
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海夜未眠 2024-10-17 08:47:56

答案是...

问题来自我的 FormView 中的 GridViewGridView 中绑定的项目之一是 Nothing/Null(BLL 中的更改,doh!)导致 GridView 破解悲伤。

由于访问代码隐藏中的 FormView 是异常发生前的最后一段非托管代码,因此这就是 Visual Studio 显示异常的位置。因此,每次我查看堆栈跟踪时,我都没有发现它是 GridView 导致顶部出现问题。我脑子里一直浮现着 FormView 这就是我正在读的内容。

And the answer is...

The problem was coming from a GridView within my FormView. One of the items being bound in the GridView was Nothing/Null (a change in the BLL, doh!) causing the GridView to crack the sads.

Because accessing the FormView in my code-behind was the last bit of unmanaged code before the exception, this is where Visual Studio was displaying the exception. Because of that, every time I had looked at the stack trace I hadn't clicked that it was a GridView causing problems at the top. I had FormView stuck in my head and that's what I was reading.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文