0

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)
Pauli Østerø
  • 6,878
  • 2
  • 31
  • 48
David
  • 1,940
  • 3
  • 17
  • 30

1 Answers1

0

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.

David
  • 1,940
  • 3
  • 17
  • 30