Postback problem in ASP.NET

I have an asp.net label control with its Visible property value set to false. In the code, I set its visibility to true / false based on whether the user is logged in or not. The strange behavior is that during postbacks, the code code executes and sets the label visibility value for anything, and then performs markup and sets the label visibility to false. For requests without postback, the status specified by the code is not overwritten. Forgive my ignorance, but is something important missing?

+2
source share
3 answers

Familiarize yourself with the life cycle of a page and when various page events fire at runtime.

http://msdn.microsoft.com/en-us/library/ms178472.aspx

Also, I don't think the code is negligible. If it were correctly encoded, you would not run into this problem. Put it here and let's see.

+5
source

There is no code, so you may have this.

you wrap everything in your Page_Load method with

if(!Page.IsPostback) { // your code here. } 

?

+2
source

Does your Label have the attribute EnableViewState = "false"?

Read more about this attribute at http://www.w3schools.com/ASPNET/aspnet_viewstate.asp

+1
source

Source: https://habr.com/ru/post/1300192/


All Articles