访问 FormView 实例时出现 ArgumentNullException
背景:
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案是...
问题来自我的
FormView
中的GridView
。GridView
中绑定的项目之一是 Nothing/Null(BLL 中的更改,doh!)导致GridView
破解悲伤。由于访问代码隐藏中的
FormView
是异常发生前的最后一段非托管代码,因此这就是 Visual Studio 显示异常的位置。因此,每次我查看堆栈跟踪时,我都没有发现它是 GridView 导致顶部出现问题。我脑子里一直浮现着FormView
这就是我正在读的内容。And the answer is...
The problem was coming from a
GridView
within myFormView
. One of the items being bound in theGridView
was Nothing/Null (a change in the BLL, doh!) causing theGridView
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 aGridView
causing problems at the top. I hadFormView
stuck in my head and that's what I was reading.