4
votes

I have a user control on a web form that is declared as follows:

<nnm:DeptDateFilter ID="deptDateFilter" runat="server" AllowAllDepartments="True" />

In the code-behind for this control, AllowAllDepartments is declared as follows:

internal bool AllowAllDepartments { get; set; }

Yet when I view the page, and set a breakpoint in the control's Page_Load event handler, my AllowAllDepartments property is always false. What are possible reasons for this?

BREAKING NEWS: Even setting the property programmatically has no effect on the property value when I hit my breakpoint in Page_Load of the control. Here is the Page_Load of the host page:

deptDateFilter.FilterChanged += deptDateFilter_FilterChanged;
if (!IsPostBack)
{
    deptDateFilter.AllowAllDepartments = true;
    PresentReport();
}
4
did you ever figure this one out? - Peter

4 Answers

2
votes

Try adding the property value to the ViewState:

protected bool AllowAllDepartments 
{
   get
   {
      if (ViewState["AllowAllDepartments"] != null)
         return bool.Parse(ViewState["AllowAllDepartments"]);
      else
         return false;
   }
   set
   {
      ViewState["AllowAllDepartments"] = value;
   }
}

EDIT Furthermore, you may want to handle the control's PreRender event, to see whether the the control's property has been correctly set there or not.

0
votes

Make the property bindable like:

[Bindable(true), Category("Appearance"), DefaultValue(false)]
internal bool AllowAllDepartments { get; set; }
0
votes

Just out of curiosity... does it work OK if you don't use the get;set; shortcut?

private bool _allowAllDepartments;
public bool AllowAllDepartments
{
    get { return _allowAllDepartments; }
    set { _allowAllDepartments = value;}
}
0
votes

Have you tried making the property public?