Skip to main content

Page init event in asp.net

Init is actually a event which is available for every individual control on a Asp.Net page. So you can use this event for any of the control on your page or use it for Page as well.
Page_Init event is fired before the Page_Load, We can perform here task related to user authentication and change master page applied to the page. This may also be useful for changing theme of the pages.
protected void Page_Init(object sender, EventArgs e)
{
int LoginId = Convert.ToInt32(SqlHelper.ExecuteScalar(Config.ConnectionStringName, "Check_User_Logged_In", Convert.ToInt32(Session["LoginUserId"]),Convert.ToString(Session.SessionID)));
if (LoginId == 0)
{
Session.Abandon();
Server.Transfer("Default.aspx");
}
}

If you are not done yet MSDN's Reference waiting for you.

Comments

Popular posts from this blog