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.

Advertisements

Say something : I accept all the "Humer&Critic"

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s