472,126 Members | 1,463 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,126 software developers and data experts.

Back button classic

I have come across a strange behaviour in ASP or rather it could be a
HTML or Browser Issue. The browser here is IE.

The requirement is to re-load the page whenever user click back button
of the browser.

I thought the solution is simple enough: Just set the page to expired,
maintain no cache and Yo! when user clicks back button browser by
default should load fresh copy from server.

But I came across the catch when the page has got a form with method
POST and has an submit button. The catch is that When user hit submit
button on Page1 and then click another button that redirect him to
page2. Now If the Back button is pressed Browser throws the error that
Page can not be displayed.

Can someone please help... what is the cause here & how this can be
rectified?

Here are the sample for your reference:
ASP code for main page 1.asp

<%@ LANGUAGE="VBSCRIPT"%>
<%OPTION EXPLICIT%>
<%
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1
Response.Buffer = True
%>
<html>
<head>
<script language=javascript>
function btn2Clicked()
{
document.location="2.asp";
}
function SubmitClicked()
{
//alert("hello");
//document.Form1.submit();
//document.clear;
}
</script>
</head>
<body>
<form action=1.asp method=post ID="Form1" target=_self
onsubmit="SubmitClicked()">
<input type=button name=btn2 onclick=btn2Clicked() value=".."
ID="Button1">
<br>
<input type=text value=<%=now()%ID="Text1" NAME="Text1">
<br>
<%Response.Write(now)%>
<br>
<input type=submit name=btnSubmit value=Submit ID="Submit1">
</form>
</body>
</html>

---------------------------------------
ASP code for Page2 (2.asp)

<%@ LANGUAGE="VBSCRIPT"%>
<%OPTION EXPLICIT%>
<%
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1
Response.Buffer = True
Response.Write("<BR>")
Response.Write(now)
Response.Write(" Lets hit back now..")
%>
YOU CAN SIMULATE THE BEHAVIOUR AS STATED BELOW
ON PAGE 1.ASP -CLICK SUBMIT -CLICK BUTTON ".." -CLICK BACK ON
BROWSER

-----------------------
Best Luck
-----------------------

Aug 2 '06 #1
1 2067
HELP PLZ..
ni**********@gmail.com wrote:
I have come across a strange behaviour in ASP or rather it could be a
HTML or Browser Issue. The browser here is IE.

The requirement is to re-load the page whenever user click back button
of the browser.

I thought the solution is simple enough: Just set the page to expired,
maintain no cache and Yo! when user clicks back button browser by
default should load fresh copy from server.

But I came across the catch when the page has got a form with method
POST and has an submit button. The catch is that When user hit submit
button on Page1 and then click another button that redirect him to
page2. Now If the Back button is pressed Browser throws the error that
Page can not be displayed.

Can someone please help... what is the cause here & how this can be
rectified?

Here are the sample for your reference:
ASP code for main page 1.asp

<%@ LANGUAGE="VBSCRIPT"%>
<%OPTION EXPLICIT%>
<%
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1
Response.Buffer = True
%>
<html>
<head>
<script language=javascript>
function btn2Clicked()
{
document.location="2.asp";
}
function SubmitClicked()
{
//alert("hello");
//document.Form1.submit();
//document.clear;
}
</script>
</head>
<body>
<form action=1.asp method=post ID="Form1" target=_self
onsubmit="SubmitClicked()">
<input type=button name=btn2 onclick=btn2Clicked() value=".."
ID="Button1">
<br>
<input type=text value=<%=now()%ID="Text1" NAME="Text1">
<br>
<%Response.Write(now)%>
<br>
<input type=submit name=btnSubmit value=Submit ID="Submit1">
</form>
</body>
</html>

---------------------------------------
ASP code for Page2 (2.asp)

<%@ LANGUAGE="VBSCRIPT"%>
<%OPTION EXPLICIT%>
<%
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1
Response.Buffer = True
Response.Write("<BR>")
Response.Write(now)
Response.Write(" Lets hit back now..")
%>
YOU CAN SIMULATE THE BEHAVIOUR AS STATED BELOW
ON PAGE 1.ASP -CLICK SUBMIT -CLICK BUTTON ".." -CLICK BACK ON
BROWSER

-----------------------
Best Luck
-----------------------
Aug 3 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by A.M | last post: by
1 post views Thread by Johan Nedin | last post: by
29 posts views Thread by Tom wilson | last post: by
8 posts views Thread by Tracey | last post: by
182 posts views Thread by Jim Hubbard | last post: by
5 posts views Thread by Stephanie Le Gall | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.