I have an asp.net label control with its Visible property set to false. In the code-behind I'm setting its visibility to true/false based on whether the user has logged in or not. A weird behavior is that on postbacks, the code-behind executes and sets the value of the label's visibility to whatever, and then the markup executes and sets the label's visibility to false. On non-postback requests, the status set by the code-behind is not overwritten. Pardon my ignorance, but am I missing something important?
+1
A:
There's no code posted so you might already have this.
are you wrapping everything in your Page_Load method with
if(!Page.IsPostback)
{
// your code here.
}
?
John Boker
2009-02-25 05:01:17
Yeah, I've taken care of checking IsPostback.
Prakash
2009-02-25 05:05:03
+3
A:
Get to know the page lifecycle, and when the various page events are fired by the runtime.
http://msdn.microsoft.com/en-us/library/ms178472.aspx
Also, I don't think the code is insignificant. If it were coded properly, you wouldn't be experiencing this problem. Put it up here and let us have a look.
Jason
2009-02-25 05:08:41
+1
A:
does your Label has a EnableViewState="false" attribute?
Learn more on this attribute at http://www.w3schools.com/ASPNET/aspnet_viewstate.asp
mangokun
2009-02-25 05:13:00
It was just one of those queer things a developer faces occasionally. Weirdly, a machine restart fixed it. Would you believe it?! Thanks for your inputs anyway.
Prakash
2009-03-04 08:15:18