Thursday, 15 November 2012

Disable Browser Back Button Programmatically

Disable Browser Back Button Programmatically

Today I will show how to Disable Back Button of Browser Programmatically.


We know that browser's back button can not be disabled because browser resides at user's machine and not on Server. All we can do is to prevent a page for being cached. So if a page is not being cached at client then browser back button will not allow a user to navigate to that page. 

How to do this:

Suppose you dont want the user to navigate to this Page1.aspx from Page2.aspx.

Use following 3 lines in HEAD section (HTML view) of Page1.aspx

<meta http-equiv="cache-control" content="no-store"/>

<meta http-equiv="expires" content="0"/>

<meta http-equiv="pragma" content="no-cache"/>

Then in the code behind inside Page_Load  event of Page1.aspx:


Response.Buffer = True

Response.ExpiresAbsolute = DateTime.Now().AddDays(-1)

Response.Expires = 0

Response.CacheControl = "no-cache"

C # (C Sharp)


Response.Buffer = true;

Response.ExpiresAbsolute = DateTime.Now().AddDays(-1);

Response.Expires = 0;

Response.CacheControl = "no-cache"; 

No comments:

Post a Comment

Thank You for Your Comments. We will get back to you soon.

back to top