Disable back button in browser

11 views
Skip to first unread message

pallavi kondapure

unread,
Nov 24, 2009, 3:35:18 AM11/24/09
to dotnetde...@googlegroups.com

Hi All,
 
I have a web page ,basically content page that is using AJAX controls(in .Net 3.5) ,Now my requirement is to disable back button in the browser .I have put

window.history.forward();

I am calling this code on onload  in javascript
window .onload
 
This  code works the first time the page is loaded.but when i click submit button a gridview is shown in the same page ,then when I click on the Back Button of the browser the following message appears
 
"Warning: Page has Expired "
 
I want to show the same page when the user clicks the browser Back button.
Kindly Suggest
 
Thanks in advance
Pallavi.K
 
 
 

 

Raghupathi Kamuni

unread,
Nov 24, 2009, 7:46:18 AM11/24/09
to dotnetde...@googlegroups.com
Browser "Back Button" is not meant to go forward.......

Brynn V1.0.0

unread,
Nov 28, 2009, 12:29:39 AM11/28/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I am trying to fully understand. I am guessing that when you click
submit that you are wanting it to update something, and continue
to "show the same page" ... i.e. the submit button is really there
to trigger the update through AJAX?

If you are sending the update through AJAX to like a handler (.ashx)
or something ... try changing the submit button to just an
ordinary button with a javascript function that triggers the AJAX.

Or, may have to give a few more details on exactly what you are
trying to do on the page ...
1. what it looks like when it loads
2. what you are wanting to do when button clicked (and is that
going through Ajax)
3. what do you want the page to look like after the button click ...
just like it did on load?

Good luck :)

P.S. All code, information, and/ or advice is for entertainment
purposes only :)

pallavi kondapure

unread,
Nov 27, 2009, 6:28:48 AM11/27/09
to dotnetde...@googlegroups.com
Thanks for the info..
Could you please suggest the solution for this....
 
Regards

Jamie Fraser

unread,
Nov 30, 2009, 5:52:59 AM11/30/09
to dotnetde...@googlegroups.com
Yeah, the best solution is don't try and disable the back button. It is defined behaviour which shouldn't be tampered with.

Raghupathi Kamuni

unread,
Nov 30, 2009, 6:44:26 AM11/30/09
to dotnetde...@googlegroups.com
Method 1) Client Side Javascript
========================
<script type = "text/javascript" >
function disableBackButton()
{
window.history.forward();
}
setTimeout("disableBackButton()", 0);
</script>
 
call disableBackButton() onload of the page
 
Method 2) Codebehind
=================
Override OnPreRender and register the above script
 
Method 3) Disabling browser caching
===========================
By disabling browser caching or cache either in Page_load event or in Page_Init event
 
checkout this for details
Reply all
Reply to author
Forward
0 new messages