Asp.net 访问FormView实例时ArgumentNullException

Asp.net 访问FormView实例时ArgumentNullException,asp.net,vb.net,argumentnullexception,Asp.net,Vb.net,Argumentnullexception,背景: 我有一个ASP.NET页面,其中包含大量用户控件。有2个用户控件是感兴趣的。根据之前选择的记录,我需要显示其中一个或两个都不显示 在用户控件中,我需要设置FormView中某些控件的属性。因此,在我后面的用户控制代码中,我有一些类似于以下内容的属性: Private ReadOnly Property phSectionReports() As PlaceHolder Get Return fvConfirmationReport.FindControl("phS

背景:

我有一个ASP.NET页面,其中包含大量用户控件。有2个用户控件是感兴趣的。根据之前选择的记录,我需要显示其中一个或两个都不显示

在用户控件中,我需要设置FormView中某些控件的属性。因此,在我后面的用户控制代码中,我有一些类似于以下内容的属性:

Private ReadOnly Property phSectionReports() As PlaceHolder
    Get
        Return fvConfirmationReport.FindControl("phSectionReports")
    End Get
End Property
问题是:

我对这处房产有问题。有时返回Nothing/Null,有时抛出NullArgumentException,消息为“值不能为Null。参数名称:container”。尝试引用fvConfirmationReport变量时出现异常。fvConfirmationReport是页面本身中我的FormView的ID

因此,我确实在寻找需要寻找的东西如果有任何想法什么样的条件(例如页面周期中的阶段等)可能导致这种情况?

下面包括一个堆栈跟踪示例。
ASP.NET 3.5 SP1,VB.NET

谢谢

堆栈跟踪:

   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)
答案是

问题来自我的
FormView
中的
GridView
GridView
中绑定的一个项目为Nothing/Null
(BLL中的一个更改,doh!),导致
GridView
破解SAD

因为访问my code behind中的
FormView
是异常之前的最后一位非托管代码,所以Visual Studio在这里显示异常。因此,每次我查看堆栈跟踪时,我都没有点击它是一个
GridView
导致顶部出现问题。我的
FormView
卡在我的脑袋里,这就是我正在读的东西