aliensurfer
aliensurfer

Reputation: 1640

Postback issue in ASP.NET

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?

Upvotes: 2

Views: 1787

Answers (3)

mangokun
mangokun

Reputation: 5603

does your Label has a EnableViewState="false" attribute?

Learn more on this attribute at http://www.w3schools.com/ASPNET/aspnet_viewstate.asp

Upvotes: 1

Jason
Jason

Reputation: 15931

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.

Upvotes: 5

John Boker
John Boker

Reputation: 83709

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.
}

?

Upvotes: 2

Related Questions