Postback issue in ASP.NET

与世无争的帅哥 提交于 2019-12-08 00:12:24

问题


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:


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.




回答2:


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

?




回答3:


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

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



来源:https://stackoverflow.com/questions/584747/postback-issue-in-asp-net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!