User control does not receive the declarative value of the property

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

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

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

 internal bool AllowAllDepartments { get; set; } 

However, when I browse the page and set a breakpoint in the Page_Load control event handler, my AllowAllDepartments property AllowAllDepartments always false. What are the possible reasons for this?

NEWS IDENTIFICATION: Even setting a property programmatically does not affect the value of the property when I hit my breakpoint in the Page_Load of the control. Here is the page_page of the main page:

  deptDateFilter.FilterChanged += deptDateFilter_FilterChanged; if (!IsPostBack) { deptDateFilter.AllowAllDepartments = true; PresentReport(); } 

strong text

+4
source share
4 answers

Try adding a 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 In addition, you can handle the PreRender control event to check if the control property is set correctly or not.

+2
source

Make the property binding, for example:

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

Just out of curiosity ... this works fine unless you use get; set; Label?

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

Did you try to make the publication public?

0
source

All Articles