About the author

Vijay Kodali
E-mail me Send mail

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2024

Disable Browser Back Button in ASP.NET

The browser back button cannot be disabled as the browser security will not allow this. If you want user to stay on the same page, even if user presses back button, try this java script..

<script language="JavaScript">
javascript:window.history.forward(1);
</script>

What if the JavaScript is disabled by the client, then this code doesn't work. And also it works great in IE, but not in other browsers. So I do not highly recommend using this.

 

Here is another solution for back button problem..

Add this code to Page_load

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now); 

 

The above code will disable page cache. Since the page is not being cached on the browser, the page will be reloaded when the user hits the back button.


Posted by vijay on Thursday, April 24, 2008 9:38 PM
Permalink | Comments (7) | Post RSSRSS comment feed

Comments

Ritesh Shah India

Friday, March 25, 2011 3:08 AM

Ritesh Shah

I have tried this code it useful to you
try id

write this code in master page in page load event

Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1)); Response.Cache.SetNoStore();

write this code in login page in head section
window.history.forward(-1);

Ilya Chistyakov Russia

Tuesday, October 18, 2011 1:53 AM

Ilya Chistyakov

Hi, this javascript doesn't work in IE8!!!

ritesh India

Tuesday, October 25, 2011 8:51 PM

ritesh

Hi Friend,
Sorry for late replay

Instead of write (window.history.forward(-1);) this line
write below function

function noBack() { window.history.forward() }
window.onload = noBack;
window.onpageshow = function(evt) { if (evt.persisted) noBack() }
window.onunload = function() { void (0) }

this function will help you

suresh India

Thursday, December 15, 2011 9:00 AM

suresh

It is great work !!!
thanks!!!

salomi India

Saturday, March 24, 2012 5:52 AM

salomi

Thanks a lot its working but its not working for mozilla browser..... can u give me solution

siteduct.com

Thursday, January 3, 2013 8:11 AM

pingback

Pingback from siteduct.com

ASP.Net Script Installation Service

alexatrafficracer.org

Sunday, September 15, 2013 9:52 AM

pingback

Pingback from alexatrafficracer.org

Wine Lovers Guide

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading