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
Post a Comment