Control properties changing during page processing
-
Hi, I have a page with a Panel control with its Visible property set to false in the markup. I've then got a button event handler that sets this to true. When the page renders this has somehow found its way back to false. Using some logging and debugging I've determined that the event is definately working as expected, but by the time the OnPreRender event fires the property has changed back. Can anyone explain this?
protected override void OnPreRender(EventArgs e) { log.Debug("PreRender, visible: " + AccessInfoContentPanel.Visible); base.OnPreRender(e); } private void ToggleContent() { if (AccessInfoContentPanel.Visible == false) { log.Debug("content made visible: "); AccessInfoContentPanel.Visible = true; AccessInfoContentPanel.Enabled = true; } else { log.Debug("content removed: "); AccessInfoContentPanel.Visible = false; AccessInfoContentPanel.Enabled = false; } } protected void ToggleBtn_ServerClick(object sender, EventArgs e) { ToggleContent(); }
Cheers!
-
Hi, I have a page with a Panel control with its Visible property set to false in the markup. I've then got a button event handler that sets this to true. When the page renders this has somehow found its way back to false. Using some logging and debugging I've determined that the event is definately working as expected, but by the time the OnPreRender event fires the property has changed back. Can anyone explain this?
protected override void OnPreRender(EventArgs e) { log.Debug("PreRender, visible: " + AccessInfoContentPanel.Visible); base.OnPreRender(e); } private void ToggleContent() { if (AccessInfoContentPanel.Visible == false) { log.Debug("content made visible: "); AccessInfoContentPanel.Visible = true; AccessInfoContentPanel.Enabled = true; } else { log.Debug("content removed: "); AccessInfoContentPanel.Visible = false; AccessInfoContentPanel.Enabled = false; } } protected void ToggleBtn_ServerClick(object sender, EventArgs e) { ToggleContent(); }
Cheers!
My guess is that the initial setting the panel to visible = false might be happening in the page load as well? Or perhaps you have viewstate turned off? That is where I have usually found these bugs. I have done some very similar things in ASP.net. NOTE a better way to do what you are trying to do might be to use a PlaceHolder control instead. Anyway, hope that helps. Ben
-
Hi, I have a page with a Panel control with its Visible property set to false in the markup. I've then got a button event handler that sets this to true. When the page renders this has somehow found its way back to false. Using some logging and debugging I've determined that the event is definately working as expected, but by the time the OnPreRender event fires the property has changed back. Can anyone explain this?
protected override void OnPreRender(EventArgs e) { log.Debug("PreRender, visible: " + AccessInfoContentPanel.Visible); base.OnPreRender(e); } private void ToggleContent() { if (AccessInfoContentPanel.Visible == false) { log.Debug("content made visible: "); AccessInfoContentPanel.Visible = true; AccessInfoContentPanel.Enabled = true; } else { log.Debug("content removed: "); AccessInfoContentPanel.Visible = false; AccessInfoContentPanel.Enabled = false; } } protected void ToggleBtn_ServerClick(object sender, EventArgs e) { ToggleContent(); }
Cheers!