Basically, what is happening is that the submit_Click
event is being fired after the Page_Load
. That is due to the ASP.NET page life cycle.
The basic order of events is the following:
1 - Init
2 - Load (Page_Load is fired)
3 - Control Events (submit_Click is fired)
4 - Load Complete
5 - Pre_Render
6 - Render
You have two options here.
1 - Use the LoadComplete handler:
protected override void OnLoadComplete(EventArgs e)
{
base.OnLoadComplete(e);
//Label Logic here
}
2 - Use the OnPreRender:
protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); //Label Logic here }