Vivek Thakur

Chaotically Complex

  Home  |   Contact  |   Syndication    |   Login
  105 Posts | 1 Stories | 504 Comments | 65 Trackbacks

News



Archives

ASP.NET Ventures

************************************************************************************

NOTE: This post has been updated and moved to:

http://www.codeasp.net/blogs/vivek_iit/microsoft.net/19/-disable-back-browser-button-aspnet

Please visit the above link to check the latest version of the post

************************************************************************************

The "Back" browser button (or for that matter any other browser button) cannot be actually disabled by a web application as the security context will not allow this (think of what nasty things could happen if web applications can remove buttons from client browsers!)

What we can do is to somehow make sure that browser does not cache the web pages (which will cause the"Back" "Forward" buttons to grey out), and this can be easily done by expiring the Response. The code for this has slightly changed in ASP.NET 2.0 (there is a new HttpCachePolicy class) :

   /*
    * Code disables caching by browser. Hence hitting the back browser button
    * causes the Page_Load event to fire again.
    */
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now); //or a date much earlier than current time

In ASP.NET 1.x the code was:

   Response.CacheControl = "no-cache";
   Response.AddHeader("Pragma","no-cache");
   Response.Expires = -1;

This will make the browser go to the server everytime the back button is clicked (for that particular page) and prevent any caching of the pages.

posted on Saturday, February 24, 2007 1:39 AM

Feedback

# re: "Disable" Back Browser Button ASP.NET 3/7/2007 2:17 PM vartika
this code has no effect.

# re: "Disable" Back Browser Button ASP.NET 3/7/2007 3:59 PM Vivek
Which code? Both the above versions are working. Let me know the details on whats not working at your end.

Vivek

# re: "Disable" Back Browser Button ASP.NET 3/7/2007 11:47 PM Justin Andrews
The above code for asp.net 1.x has no effect for me either... I am placing it in the page_load event.

Thanks,

JAndrews

# re: "Disable" Back Browser Button ASP.NET 4/27/2007 1:08 AM miks
unfortunately your code is not working

# re: "Disable" Back Browser Button ASP.NET 7/26/2007 5:47 PM mary williams
how do i get my back browers back?it is not on my toolbar anymore

# re: "Disable" Back Browser Button ASP.NET 9/10/2007 11:39 AM Tarique
this code is not working even i m giving on page load event out signout or pageload of homepage

# re: "Disable" Back Browser Button ASP.NET 9/25/2007 10:26 PM zMoe
Try this:

<%
Response.Buffer = true;
Response.Expires = 0;
Response.ExpiresAbsolute = DateTime.Now.AddDays( -1 );
Response.CacheControl = "no-cache";
%>

# re: "Disable" Back Browser Button ASP.NET 10/6/2007 4:45 PM find me
its working man....... hi friends it expries the page not disable the back button....... u can use it for more security..... good work man.......

# re: "Disable" Back Browser Button ASP.NET 10/12/2007 9:19 PM Rachid
I nave 2.0 and I put just:
Response.Cache.SetCacheability(HttpCacheability.NoCache);

In code brhind in : Page_Init event and it s working perfectly I mean the page doesn t cache itself, i didn t check the back button.

Thanks a lot.



# re: "Disable" Back Browser Button ASP.NET 10/25/2007 2:10 PM roji
Hai,
I tried these codes in my application but once the back button is clicked it's displaying an error page.But once again i click the back button, the previous page will come back.Actually i want the user to logout or provide an default session expire page once the user trying to navigate to back button.Currently in my application after the user is logged in they can view the start page.if i tried to click the back button from browser,it will take me to login screen.And again if i click the forward button from browser my application will take me to start page as i do not need this thing should happen.How i can able to overcome from this sistuation.Please help me.

Thanks.

Response.Buffer = true;
Response.Expires = 0;
Response.ExpiresAbsolute = DateTime.Now.AddDays( -1 );
Response.CacheControl = "no-cache";

and also

Response.Cache.SetCacheability(HttpCacheability.NoCache);

inside Page_PreInit of my login page and start page each page of my application



# re: "Disable" Back Browser Button ASP.NET 10/26/2007 9:08 PM Atif
holy shit batman, it works !

Response.Cache.SetCacheability(HttpCacheability.NoCache);

# re: "Disable" Back Browser Button ASP.NET 11/6/2007 12:33 PM Naveen Reddy
Hi,


Protected void Page_Init(object Sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
}
this is enough to remove the bwoser cache in asp.net( with Help of c#.net)

# re: "Disable" Back Browser Button ASP.NET 11/19/2007 11:29 AM behrouz talebi
Hi,
I have used of asp.net 2005 and IE 7.0 in vista.But I can not disable back buttom in IE for login.aspx page on my website.

Please advise me.

Best Regards,
Behrouz Talebi.

# re: "Disable" Back Browser Button ASP.NET 11/26/2007 9:36 AM Sam
Cheers Vivek,
this works perfectly as i enable/disable certain validators on my page using ajax, now the page reloads properly if i press the 'back' button. Before, the page would load out of cache and only have the validators enabled that i had chosen on the first initial load thereby throwing them out of wack.

All good now!

# re: "Disable" Back Browser Button ASP.NET 11/27/2007 9:29 AM twiggers
It is disingenuous to call this disabling the "back" button in the browser. It will force the page to load from the server, since it is not in the client-side cache.

If the user wants to move backward through the pages your application needs to manage state properly and allow for this possibility. This misuse of the browser cache settings is just a hack.

# re: "Disable" Back Browser Button ASP.NET 12/4/2007 4:30 PM Aneesh
How can I implement thsi code to prevent caching in dot net aspx projects using VB scripting.

# re: "Disable" Back Browser Button ASP.NET 12/5/2007 4:51 PM singh
it is not working. i have put all the code in page_load as well as page_init event in 2.0 version

# re: "Disable" Back Browser Button ASP.NET 12/6/2007 12:43 PM eric.wen
hi , in a.aspx, try js: window.location.replace('b.aspx'); it really works for me.

# re: "Disable" Back Browser Button ASP.NET 12/6/2007 4:03 PM rajesh
Hi this code not properly work in asp.net 2.0 pls reply where this code is add.

# re: "Disable" Back Browser Button ASP.NET 12/14/2007 12:16 PM manisha
Please send me the code

# re: "Disable" Back Browser Button ASP.NET 12/18/2007 6:52 PM Paresh Rathod
Hi Dear,

Following code:

Protected void Page_Init(object Sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
}

In following scenario its not working for my web site.

1.Login
2. Now visit any pages of my web site.
3.log out
4. now login again with other user name and password.
5. now click on back button, its navigating to all the pages what were visited by previous user.

But suppose one user is logged in and after visiting pages, logged out and close the browser.
Again open the new browser and login. After pressing back button. He is not able to visit the pages, what were visited by previous user.

Means cache is not cleared until the browser is closed. Once browser is closed cache is cleared.

If u have any solution of this problem, please get back to me.

Thanks in advance

Paresh Rathod



# re: "Disable" Back Browser Button ASP.NET 12/20/2007 4:36 PM debo
none of the codes r working. the code fits well but doesnt do nething. it is not working at all

# re: "Disable" Back Browser Button ASP.NET 12/20/2007 4:40 PM Amit Malviya
Its Not Working in my Applications::::


Protected void Page_Init(object Sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
}

give me ..... Other Way if any

Thanx

Amit

# re: "Disable" Back Browser Button ASP.NET 12/29/2007 11:36 AM Niraj
Protected void Page_Init(object Sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
}

This Above Code Is Working But It Fall On Refresh Button It Enter Login In Page

# re: "Disable" Back Browser Button ASP.NET 1/10/2008 11:55 AM Frank
Protected void Page_Init(object Sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
}

The code is work but cannot "disable" Refresh button. And also, the "Refresh" is counted as "PostBack".

# re: "Disable" Back Browser Button ASP.NET 1/15/2008 10:26 PM Andy
does not work on mine either. What Im trying to do is have the page say that its EXPIRED when the user clicks the back button, but none of this code works.

# re: "Disable" Back Browser Button ASP.NET 1/17/2008 12:08 PM sdsdsd
Salo Tum sab pagal ho, Code is not working...

# re: "Disable" Back Browser Button ASP.NET 1/17/2008 1:56 PM techy
saale sab gadhe hain....

# re: "Disable" Back Browser Button ASP.NET 1/17/2008 1:57 PM techy
abe kuch to dhang seekho....
kuch bhi likh dete ho

# re: "Disable" Back Browser Button ASP.NET 1/21/2008 9:21 PM zee
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">

# re: "Disable" Back Browser Button ASP.NET 1/24/2008 12:35 PM Sajjad
Simply use
<script language="JavaScript">
<!--
javascript:window.history.forward(1);
//-->
</script>


working for me :)

# re: "Disable" Back Browser Button ASP.NET 1/24/2008 5:44 PM Aarti
Simply use in load event of the page.


Response.ExpiresAbsolute=DateTime.Now.AddDays(-1d);
Response.Expires =-1500;
Response.CacheControl = "no-cache";
if(Session["Seesion"] == null)
{
Response.Redirect("errorpage.aspx",false);
}
else
{

}

# re: "Disable" Back Browser Button ASP.NET 2/7/2008 7:32 PM Ruby Afsha
Try this on the page where u want to disable the back button for eg Page1.aspx :

<body onunload="javascript:window.location.replace('Page1.aspx')">

# re: "Disable" Back Browser Button ASP.NET 2/8/2008 12:25 PM prem
whene i am clicking browser back button ..It want to show error page(not a custome error page)..it want to display internet explorer error page..pleae give code for this..thanks

# re: "Disable" Back Browser Button ASP.NET 2/29/2008 12:04 PM karlo_cor
try this link.

http://support.microsoft.com/kb/323290

# re: "Disable" Back Browser Button ASP.NET 3/20/2008 2:46 PM dil
Ya its working. suppose u want to prevent going back from a particular page say default3.aspx type this code in source file's body .The code is:
onunload="javascript:window.location.replace('Default3.aspx')" .

# re: "Disable" Back Browser Button ASP.NET 4/4/2008 3:48 PM Suresh
<%
Response.Buffer = true;
Response.Expires = 0;
Response.ExpiresAbsolute = DateTime.Now.AddDays( -1 );
Response.CacheControl = "no-cache";
%>
Above Code is working fine..
THanks


# re: "Disable" Back Browser Button ASP.NET 4/7/2008 1:28 PM awanish
Please send me complete code of disable backword browser.
the above code in not working fine
thanks


# re: "Disable" Back Browser Button ASP.NET 4/15/2008 4:23 PM LightSpeed6
Assume Page A calls Page B and you dont want to go back from page B to Page A. Simply include this code in Page A.

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

# re: "Disable" Back Browser Button ASP.NET 4/16/2008 4:54 PM milsom
does this code work with visual studio 2008???

# re: "Disable" Back Browser Button ASP.NET 4/18/2008 10:19 PM Joe Gakenheimer
This garbage doesn't work either.

# re: "Disable" Back Browser Button ASP.NET 5/24/2008 12:03 AM Disappointed
Works great for IE but what about firefox and safari? Doesn't work!

# re: "Disable" Back Browser Button ASP.NET 5/27/2008 1:32 AM Izzeldin
It works when i use visual studio 2005, Thanks

# re: "Disable" Back Browser Button ASP.NET 6/3/2008 1:09 AM ev
Works great, thanks.

# re: "Disable" Back Browser Button ASP.NET 6/4/2008 1:18 AM JS
To all the people that said "Works Great"

It does ONLY on IE not in FireFox.

Can anyone recomend a solution that works in FF.

Thanks

# re: "Disable" Back Browser Button ASP.NET 7/8/2008 9:14 PM KBOBCE
This has been tested OK for MSIE, FireFox, Safari and Opera
(up to june 2008 last versions)

<html><head>
<script type="text/javascript">
window.history.forward();
function noBack(){ window.history.forward(); }
</script>
</head>
<body onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload="">
...
</body></html>

NB : window.history.forward(1) is wrong as forward method has no param. Use window.history.go(1) instead.

# re: "Disable" Back Browser Button ASP.NET 7/10/2008 2:39 PM No woking
This is now woking

# re: "Disable" Back Browser Button ASP.NET 7/15/2008 9:11 PM KBOBCE
You might prefer this syntax, easier to include within the Head tags (and xhtml friendly) :

<script type="text/javascript">
function noBack(){window.history.forward();}
noBack();
window.onload=noBack;
window.onpageshow=function(evt){if(evt.persisted)noBack();}
window.onunload=function(){void(0);}
</script>

# re: "Disable" Back Browser Button ASP.NET 7/17/2008 5:35 AM Ben
Bullshit it that code is not working on me

# re: "Disable" Back Browser Button ASP.NET 7/18/2008 11:27 PM Mike Martinet
For ASP 2.0 Using the Javascript approach from KBOBCE works in the aspx page and is easier than modifying the codebehind file.
Thanks


# re: "Disable" Back Browser Button ASP.NET 7/22/2008 12:49 PM tody
Its working great.....


# re: "Disable" Back Browser Button ASP.NET 7/22/2008 8:54 PM Bhavesh
It is working very well

Thanks

# re: "Disable" Back Browser Button ASP.NET 8/12/2008 11:11 AM Ana
Working Fine...

# re: "Disable" Back Browser Button ASP.NET 8/12/2008 5:53 PM aasd
howle laounde hai saale ,its not working 2.0

# re: "Disable" Back Browser Button ASP.NET 8/20/2008 6:17 PM ninu
this code is not working

# re: "Disable" Back Browser Button ASP.NET 8/25/2008 11:47 AM venu
working fine

# re: "Disable" Back Browser Button ASP.NET 9/6/2008 4:29 PM Gi Viswa
Code by KBOBCE is working fine

# re: "Disable" Back Browser Button ASP.NET 9/10/2008 2:24 PM Prasad
This code is not disabling the back button function but is making the previous's previous page expired.Means not exactly the previous page but the pevious page of the previous page

# re: "Disable" Back Browser Button ASP.NET 9/11/2008 8:35 PM yangamuniprasad
Exllent blog it is

i get success by seeing this site for disable code is woking

thanks alot

# Disable Back button in the browser 9/11/2008 8:45 PM yangamuniprasad
Try this code on the page where u want to disable the back button for eg Page1.aspx :

<body onunload="javascript:window.location.replace('Page1.aspx')">


its nice code its working proper way i was tryed different lenthy codes but fails, just i try this above code its working very beautifully. my problem is resolved.


thanks to this blog and its members.

# re: "Disable" Back Browser Button ASP.NET 9/15/2008 9:29 AM arun
worked in asp.net 3.5 not in 1.1

# re: "Disable" Back Browser Button ASP.NET 9/17/2008 11:49 AM Renu
Code is not working

# re: "Disable" Back Browser Button ASP.NET 9/23/2008 2:50 PM sandy
its Working Gr8
Thanx

# re: "Disable" Back Browser Button ASP.NET 9/23/2008 7:23 PM ujjwal soni
Thanks,


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

Its working great for me.

Cheers!!!

Ujjwal B Soni

# re: "Disable" Back Browser Button ASP.NET 9/26/2008 3:58 PM smija
Its working..........
thanks..

# re: "Disable" Back Browser Button ASP.NET 9/27/2008 11:44 AM saloo
hi sajjid
ur coding is working thanks

# re: "Disable" Back Browser Button ASP.NET 10/6/2008 11:02 PM sharath
oyee guys just try this out .....101% sure about this
Response.Cache.SetExpires(DateTime.Now)
Response.Cache.SetCacheability(HttpCacheability.NoCache)


put this in the first lines of page_load sub procedure of ur desired page .... and see the difference.....


you 'll say that silvery's presence creates a difference....

JUST GO BY THAT

# re: "Disable" Back Browser Button ASP.NET 10/10/2008 1:18 AM taimoor
thanks brov Ujjwal B Soni
its working for me as well

again tahnks for ur help

# re: "Disable" Back Browser Button ASP.NET 10/11/2008 2:27 PM rakesh
no one code is work please send me other coad ...

thanks in advance..

# re: "Disable" Back Browser Button ASP.NET 10/20/2008 9:45 PM Neo
<script type="text/javascript" language="javascript">
javascript:window.history.forward(1);
</script>

This work fine for me too.. thanx..

# re: "Disable" Back Browser Button ASP.NET 10/23/2008 8:03 AM basikal
hi sajjad...

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

ur codes is working for me thanks... :)

# re:"Disable" Back Browser Button ASP.NET 7/15/2008 9:11 PM KBOBCE 10/24/2008 4:50 PM sathish
excellent code.thats working excellently

# re: "Disable" Back Browser Button ASP.NET 10/25/2008 12:30 AM Jai
Thanks it works fine

# re: "Disable" Back Browser Button ASP.NET 11/14/2008 11:19 AM raj
not working

# re: "Disable" Back Browser Button ASP.NET 11/17/2008 9:30 AM dean
i nd coding for C# regard of Disable back..
i have done alot of coding..it still unable to use it...
any ideas? can help to guide me using C#..and where to paste it in..?thx.!!!

# re: "Disable" Back Browser Button ASP.NET 11/18/2008 1:46 PM andrew
what kind of performance is lost using this code?

# re: "Disable" Back Browser Button ASP.NET 11/24/2008 8:44 PM Magu
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddDays(-2));

Its not working

# re: "Disable" Back Browser Button ASP.NET 12/3/2008 12:17 AM Roc1
protected void Page_Init(object Sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
}

doesn't work. oh well, it's an ugly hack anyway.

# re: "Disable" Back Browser Button ASP.NET 12/9/2008 12:44 PM santosh
its not working friends is there any way to do that in .net 2.0

# re: "Disable" Back Browser Button ASP.NET 12/17/2008 11:18 AM Aleya
Your codes is working for me thanks... :)

# re: "Disable" Back Browser Button ASP.NET 12/17/2008 9:28 PM RequinMalin
What about if the Javascript is disabled by the client all the solutions like:
javascript:window.history.forward(1);
or
<body onunload="javascript:window.location.replace('Page1.aspx')">
will be big security failures, I do not recommand using this in any sensible information case...

# re: "Disable" Back Browser Button ASP.NET 12/17/2008 10:49 PM genious
WELL, The code only work when u have dynamic contents on the page, if its a simple page, browser will still show. however when browser client needs to contact with server to get the latest contents, then this code will give erro.


code from the above post, some one was saying not working.
it only work for dynamic contents .i.e. change any combo or dropdown box value and then try to press back button.

code herer

protected void Page_Init(object Sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
}



hope it help


# re: "Disable" Back Browser Button ASP.NET 12/18/2008 8:13 PM stuti
onunload="javascript:window.location.replace('signoutt.aspx')">

this code is working fine with my asp.net project

# re: "Disable" Back Browser Button ASP.NET 12/21/2008 12:23 AM Brian
After reading a bunch of junk like this all over the internet. I decided to find a different solution (work around). Here is what I did. When the user clicks the logout button I cleared the Session and redirected them to some page (loggedout.aspx) in the loggedout.aspx page on load i put a redirect back to the main page, on the main page i check the session vars. what this does is when the user does a back button it sends them to the loggedout.aspx page and does what it did the last time it was there which is redirect it to the main page. The enduser will never see the loggedout.aspx page at all

# re: "Disable" Back Browser Button ASP.NET for master page 1/22/2009 12:44 PM rajan
hi can any one know how to implement same thing when we use master page

# re: "Disable" Back Browser Button ASP.NET 1/29/2009 3:18 PM varun
This code is not working when there is master page and content page.

# re: "Disable" Back Browser Button ASP.NET 2/4/2009 1:16 PM vamshee
Sharaths coding is working fine

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

but the code is not working on different browsers

# re: "Disable" Back Browser Button ASP.NET 2/26/2009 1:29 PM libesh
varun, in case of master page and content page
use window.history.forward(1) in the master page

# re: "Disable" Back Browser Button ASP.NET 2/28/2009 8:42 AM visva


Thx buddies, the below code works...for me.. ( Framework 2.0 )

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


# re: "Disable" Back Browser Button ASP.NET 3/6/2009 2:18 PM Larry @ candida remedies
This post is awesome... I found the solution for my problem. The code by KBOBCE is working perfectly. Thanks

# re: "Disable" Back Browser Button ASP.NET 3/9/2009 12:18 PM Pramod
Hi All,
Can i get some code to avoid pressing F5 button.

# re: "Disable" Back Browser Button ASP.NET 3/14/2009 12:56 PM sandeep
<script language="JavaScript">
<!--
javascript:window.history.forward(1);
//-->
</script>

WORKING FINE FOR ME TOO......
TAHNKS

# re: "Disable" Back Browser Button ASP.NET 3/17/2009 1:12 PM kousalya
the below code will be worked in mozilla also...jst check once.

<script type="text/javascript" language="javascript">history.go(1)</script>

or

<script language="JavaScript">
window.history.forward(0);
function setFocus(theID){
document.getElementById(theID).focus();
}
function disableSubmitButton(formObj,id){
formObj.submit();
if(document.getElementById(id)!=null)
document.getElementById(id).disabled=true;
}
</script>

# re: "Disable" Back Browser Button ASP.NET 3/18/2009 8:00 PM Cool
Thanks Ujjwal B Soni
Its working for me as too

# re: "Disable" Back Browser Button ASP.NET 3/18/2009 9:51 PM limchc
Great..code from KBOBCE really work for me.
It works in IE and Mozilla Firefox as well..

Thanks KBOBCE, your code has helped me to rectify my issue.

# re: "Disable" Back Browser Button ASP.NET 3/20/2009 4:31 PM MG
Let me explain what i need and what i am getting here.
I want when user click on Browser Back Button then page either expire or it should show some error/session expire message page as it is in any bank site(ICICI bank site).
so we need to trap button click event which i don't think is possible and if we use js: as window.history.forward() then on back button click it goes to previous page,completes life cycle and then executes the current page life cycle. which is not good as if user clicks back button then it executes previous page life cycle and if we use "Response.Cache.SetExpires(DateTime.Now);
Response.Cache.SetCacheability(HttpCacheability.NoCache)" this then also previous page load calls and it reload previous page
so is there any way to show my custom page on back button click as in icici bank site



# re: "Disable" Back Browser Button ASP.NET 4/16/2009 2:18 AM jd
I've tried KBOBCE code. I put it into the head tag and it still didn't work. any suggestions?

# re: "Disable" Back Browser Button ASP.NET 5/27/2009 6:03 PM Anitha
Hi friends,

Can anyone plzz tel me how to disable forward button

# re: "Disable" Back Browser Button ASP.NET 5/28/2009 12:51 PM sanjay,Harshali
Thanks for giving following code disable back button in asp.net

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
Response.CacheControl = "no-cache";
Response.AddHeader("Pragma", "no-cache");
Response.Expires = -1;
}

It is working fine.

# re: "Disable" Back Browser Button ASP.NET 6/4/2009 9:58 PM Ajaykumar

I have checked the above codes...
No use...

Can any one tell me how to disable back and forward button

of IE 7.0 in ASP .NET 3.5 under Windows Vista SP1?

# re: "Disable" Back Browser Button ASP.NET 6/13/2009 4:23 AM Rupesh Tiwary
I used the code::
<body onunload="javascript:window.location.replace('Page1.aspx')">
Its working right for me..
Thx.........

# re: "Disable" Back Browser Button ASP.NET 6/24/2009 7:56 AM KBOBCE
Again, for this code to work flawlessly with all browser, please insert it in the head of "every" page :
<script type="text/javascript">
function noBack(){window.history.forward();}
noBack();
window.onload=noBack;
window.onpageshow=function(evt){if(evt.persisted)noBack();}
window.onunload=function(){void(0);}
</script>

# re: "Disable" Back Browser Button ASP.NET 6/30/2009 4:26 AM Raja
working perfectly. but it is necessary to put in correct aspx page.

# re: "Disable" Back Browser Button ASP.NET 6/30/2009 4:27 AM Raja
Oooooo yes i enjoyed sssssssss working perfectly. but it is necessary to put in correct aspx page.

# re: "Disable" Back Browser Button ASP.NET 7/8/2009 6:50 AM Ratnesh
All the above code are not in proper way. May be these codes are working but they still face browser problem i.e IE6,IE7,Mozilla3.5etc. check out all this code in different browsers and then paste your valuable comment.
for any assistance use your own login rather to go for this.

# re: "Disable" Back Browser Button ASP.NET 7/10/2009 4:25 AM Pubbs
<script type = "text/javascript" >
function disableBackButton()
{
window.history .forward(1);
}
setTimeout("disableBackButton()", 0);
</script>

It works properly, i want disable back button...
plzzz give the solution ASAP

# re: "Disable" Back Browser Button ASP.NET 7/15/2009 7:57 AM New in Programming
onunload="javascript:window.location.replace('Page1.aspx')"

is working perfectly.. Thanks buddy!

# re: "Disable" Back Browser Button ASP.NET 7/16/2009 12:11 AM Chandralekha
yangamuniprasad code

onunload="javascript:window.location.replace('Page1.aspx')"

is working fine for ASP.Net 2.0

Thank U!!





# re: "Disable" Back Browser Button ASP.NET 7/31/2009 4:02 PM Iman Masihabadi
write this code on page1.aspx
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
string sb;
sb = "<script language=javascript>\n";
sb += "window.history.forward(1);\n";
sb += "\n</script>";
ClientScript.RegisterClientScriptBlock(this.GetType(), "ClientScript", sb);
}


# re: "Disable" Back Browser Button ASP.NET 8/16/2009 3:37 AM Caleb
KBOBCE's code work with IE and ASP.NET 2.0 but not with Google Chrome. Anyone have any ideas on how to fix it for Google Chrome?

# re: "Disable" Back Browser Button ASP.NET 8/26/2009 11:50 PM Amit Someshwar
Hi following code is not working if I write that in to the Page Load please Send me Suggetion about that

Response.Buffer = true;
Response.Expires = 0;
Response.ExpiresAbsolute = DateTime.Now.AddDays( -1 );
Response.CacheControl = "no-cache";


# re: "Disable" Back Browser Button ASP.NET 9/28/2009 3:16 AM Andrew M. Obial
dung it!!! IT WORKS. thanks yangamuniprasad ....

# re: How to Disable Back Browser Button in asp .net 10/21/2009 1:27 AM muruganad
description: One of the web applications after I logout when I click on back button I am able to access the admin pages I am looking to block that

Here is the solution for the problem......

Solution
------------

The "Back" browser button or any browser button cannot be actually disabled by a web application this is because the security context will not allow this

The solution is to present the browser from caching pages

<%
Response.Buffer = true;
Response.Expires = 0;
Response.ExpiresAbsolute = DateTime.Now.AddDays( -1 );
Response.CacheControl = "no-cache";
%>

or try this


Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now); //or a date much earlier than current time

In ASP.NET 1.x the code was:
Response.CacheControl = "no-cache";
Response.AddHeader("Pragma","no-cache");
Response.Expires = -1;

This causes the postback to the server everytime the back button is clicked and prevent any caching of the pages.

the above did not work in firefox this is one code that worked for me in all browsers firefox, ie opera etc

&lt;script type=&quot;text/javascript&quot;&gt;
function noBack(){window.history.forward();}
noBack();
window.onload=noBack;
window.onpageshow=function(evt){if(evt.persisted)noBack();}
window.onunload=function(){void(0);}
&lt;/script&gt;

Read more from MS site
http://support.microsoft.com/kb/234067/EN-US




# re: "Disable" Back Browser Button ASP.NET 10/22/2009 11:22 AM Arjun Urs
Thanks guys.. This worked for me.... :)
<script language="JavaScript">
<!--
javascript:window.history.forward(1);
//-->
</script>

Arjun Urs

# re: "Disable" Back Browser Button ASP.NET 10/28/2009 2:11 PM Kevster
Thanks Arjun Urs. You solution gave me exactly what I needed!

# re: "Disable" Back Browser Button ASP.NET 11/23/2009 1:59 AM skumar
salo tum sab gadhe ho. koi bhi right code nahi likha hai koi code work nahi kar raha hai.pata nahi tum sab kaise developer ban gaye


Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: