Wednesday, June 29, 2011

Check for null session

Check for null session

1 protected void Page_Load(object sender, EventArgs e)
2 {
3 if (Session["UserName"] != null)
4 {
5 //do something
6 }
7 else
8 {
9 Session.Abandon();
10 // sign out the user
11 System.Web.Security.FormsAuthentication.SignOut();
12 // redirect to the login page
13 System.Web.Security.FormsAuthentication.RedirectToLoginPage();
14 }
15 }

How to return back to a specific page in a gridview list?

How to return back to a specific page in a gridview list?

You can save the PageIndex into Session or ViewState. In the Page_Load event of GridView page you can check it first. If the session is not null, then go to that page with setting PageIndex and rebinding GridView.