c# - textbox and label won't hide during page_load -


i'm trying hide object txtdisc when lblusertype not string special_user. lbllock locked , visible when txtdisc visibility false, , vice versa.

so put inside page_load method won't function @ all.

protected void page_load(object sender, eventargs e) {     buttonvisibility(); }  private void buttonvisibility() {     if (lblusertype.text == "special_user")     {         txtdisc.visible = true;         lbllock.visible = false;     } } 

change code :

protected void page_load(object sender, eventargs e) {     if (page.ispostback == false)     {          buttonvisibility();     } }  private void buttonvisibility() {     if (lblusertype.text == "special_user")     {         txtdisc.visible = true;         lbllock.visible = false;     }     else     {         txtdisc.visible = false;         lbllock.visible = true;     } } 

by using if (page.ispostback == false) sure code inside executed @ first page load. ispostback property of asp.net page tells whether or not page on initial load or if user has perform button on web page has caused page post


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -