472,126 Members | 1,639 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.

Dealing with the Back button

I can't believe this is such an impossibility...

I have an asp.net page. It accepts data through on form fields and
includes a submit button. The page loads up and you fill out some
stuff. The submit button posts the page back to the server. The
button code detects an entry error and sends the page back to the
user. This all works.

However, if the user presses the Back button at this point, we go back
and all the form values are cleared. I've been all over the web
searching for a solution and all I can find is to either disable the
back button or clear the history so Back won't go back.

I can't get either of these to work either. I've tried adding the
javascript to the top of the body of the page:

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

I've tried adding this to the Page_Load event:

Response.Cache.SetCacheability(HttpCacheability.No Cache)

Yet I can still use the back button to go back to a blank page.

What's the solution to this problem?

Thanks!

Nov 19 '05 #1
29 3723
I suppose it wouldn't hurt to try :

<%@ OutputCache Location="None" %>

No guarantees, though.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
=====================

"Tom wilson" <ye*******@nospam.com> wrote in message
news:or********************************@4ax.com...
I can't believe this is such an impossibility...

I have an asp.net page. It accepts data through on form fields and
includes a submit button. The page loads up and you fill out some
stuff. The submit button posts the page back to the server. The
button code detects an entry error and sends the page back to the
user. This all works.

However, if the user presses the Back button at this point, we go back
and all the form values are cleared. I've been all over the web
searching for a solution and all I can find is to either disable the
back button or clear the history so Back won't go back.

I can't get either of these to work either. I've tried adding the
javascript to the top of the body of the page:

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

I've tried adding this to the Page_Load event:

Response.Cache.SetCacheability(HttpCacheability.No Cache)

Yet I can still use the back button to go back to a blank page.

What's the solution to this problem?

Thanks!

Nov 19 '05 #2
I've also tried this method:

<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">

I can use the back button all I want to return to blank pages.
Nov 19 '05 #3
You were right!!! It made no difference. :)

Thanks tho...

On Wed, 16 Feb 2005 11:07:13 -0400, "Juan T. Llibre"
<no***********@nowhere.com> wrote:
I suppose it wouldn't hurt to try :

<%@ OutputCache Location="None" %>

No guarantees, though.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
=====================

"Tom wilson" <ye*******@nospam.com> wrote in message
news:or********************************@4ax.com.. .
I can't believe this is such an impossibility...

I have an asp.net page. It accepts data through on form fields and
includes a submit button. The page loads up and you fill out some
stuff. The submit button posts the page back to the server. The
button code detects an entry error and sends the page back to the
user. This all works.

However, if the user presses the Back button at this point, we go back
and all the form values are cleared. I've been all over the web
searching for a solution and all I can find is to either disable the
back button or clear the history so Back won't go back.

I can't get either of these to work either. I've tried adding the
javascript to the top of the body of the page:

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

I've tried adding this to the Page_Load event:

Response.Cache.SetCacheability(HttpCacheability.No Cache)

Yet I can still use the back button to go back to a blank page.

What's the solution to this problem?

Thanks!


Nov 19 '05 #4
Tom wilson wrote:
I can't believe this is such an impossibility...

<snip of description of by-design behavior>

I would consider putting the form values into session upon submission. Then
add code to page_load to check the session and load the values from session
into the form elements if they exist. You'll need to work out some details,
when to clear the session vars, preventing duplicate data processing, etc.

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Nov 19 '05 #5
The HTML source:

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="TestForm.aspx.vb" Inherits="Vista.TestForm"%>
<%@ OutputCache Location="None" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>TestForm</title>
<meta content="Microsoft Visual Studio .NET 7.1"
name="GENERATOR">
<meta content="Visual Basic .NET 7.1"
name="CODE_LANGUAGE">
<meta content="JavaScript"
name="vs_defaultClientScript">
<meta
content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<%
Response.Buffer = True
Response.ExpiresAbsolute = DateTime.Now.AddDays(-1)
Response.Expires = 0
Response.CacheControl = "no-cache"
%>
<form id="Form1" method="post" runat="server">
<asp:button id="Button1" style="Z-INDEX: 101;
LEFT: 16px; POSITION: absolute; TOP: 80px" runat="server"

Text="Button"></asp:button><asp:placeholder id="PlaceHolder1"
runat="server"></asp:placeholder></form>
</body>
</HTML>

The Page_Load:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Response.Cache.SetCacheability(HttpCacheability.No Cache)
Dim x As Integer
Response.Write("Test Page<BR><BR>")
For x = 1 To 10
Radios(x) = New RadioButton
Radios(x).Text = "Radio " & x
Radios(x).ID = "Radio" & x
Radios(x).GroupName = "1"
PlaceHolder1.Controls.Add(Radios(x))
Next
Response.Cache.SetCacheability(HttpCacheability.No Cache)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
End Sub

You will notice there are no less that 4 different methods for
disabling the cache yet:

1 - Load the page, click a radio
2 - Submit
3 - Back - Goes back, regardless of the above methods, to a page with
no radios selected.

Why?

Thanks...


On Wed, 16 Feb 2005 09:50:00 -0500, Tom wilson <ye*******@nospam.com>
wrote:
I can't believe this is such an impossibility...

I have an asp.net page. It accepts data through on form fields and
includes a submit button. The page loads up and you fill out some
stuff. The submit button posts the page back to the server. The
button code detects an entry error and sends the page back to the
user. This all works.

However, if the user presses the Back button at this point, we go back
and all the form values are cleared. I've been all over the web
searching for a solution and all I can find is to either disable the
back button or clear the history so Back won't go back.

I can't get either of these to work either. I've tried adding the
javascript to the top of the body of the page:

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

I've tried adding this to the Page_Load event:

Response.Cache.SetCacheability(HttpCacheability.N oCache)

Yet I can still use the back button to go back to a blank page.

What's the solution to this problem?

Thanks!


Nov 19 '05 #6
This page can have possibly hundreds of dynamically generated controls
on it, which is why I can't lose the data with a back click. I'd have
to dynamically create an unknown number of different arrays to store
the data, possibly tons of it. This is such a basic thing to do, I
don't understand why it's completely impossible without writing reams
of code to maintain the state of the pages. I thought that's what
asp.net did inherently:

http://www.w3schools.com/aspnet/aspnet_viewstate.asp

"When a form is submitted in classic ASP, all form values are cleared.
Suppose you have submitted a form with a lot of information and the
server comes back with an error. You will have to go back to the form
and correct the information. You click the back button, and what
happens.......ALL form values are CLEARED, and you will have to start
all over again! The site did not maintain your ViewState.

When a form is submitted in ASP .NET, the form reappears in the
browser window together with all form values. How come? This is
because ASP .NET maintains your ViewState. The ViewState indicates the
status of the page when submitted to the server. The status is defined
through a hidden field placed on each page with a <form
runat="server"> control. "

I don't get why the vewstate is not maintained in this example when
the above seems to imply that this is a very basic and default
behavior of asp.net pages.

Go to any site with an online application form like for a credit card.
They never have to disable the back button or post huge messages about
"Do not hit back!!!" all over the place...

Why can't I do that here?

On Wed, 16 Feb 2005 10:51:02 -0500, "Bob Barrows [MVP]"
<re******@NOyahoo.SPAMcom> wrote:
Tom wilson wrote:
I can't believe this is such an impossibility...

<snip of description of by-design behavior>

I would consider putting the form values into session upon submission. Then
add code to page_load to check the session and load the values from session
into the form elements if they exist. You'll need to work out some details,
when to clear the session vars, preventing duplicate data processing, etc.

Bob Barrows


Nov 19 '05 #7
Hi, Tom.

I made a very simple test page,
which you can test at http://asp.net.do/test2/test2.aspx

It only has one textbox, but should work the same no
matter how many text fields you have on the page.

Check it out, and write something in the textbox.
Then, hit your browser's back button.

The text in the texbox disappears, whcih I
believe is the behavior you want, isn't it ?

If not, please let me know the behavior you want.

Source code :
test2.aspx:
=======
<%@ Page Language="VB" %>
<%@ OutputCache Location="None" %>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
</p>
</form>
</body>
</html>
============


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
=====================

"Tom wilson" <ye*******@nospam.com> wrote in message
news:ma********************************@4ax.com...
You were right!!! It made no difference. :)

Thanks tho...

On Wed, 16 Feb 2005 11:07:13 -0400, "Juan T. Llibre"
<no***********@nowhere.com> wrote:
I suppose it wouldn't hurt to try :

<%@ OutputCache Location="None" %>

No guarantees, though.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
=====================

"Tom wilson" <ye*******@nospam.com> wrote in message
news:or********************************@4ax.com. ..
I can't believe this is such an impossibility...

I have an asp.net page. It accepts data through on form fields and
includes a submit button. The page loads up and you fill out some
stuff. The submit button posts the page back to the server. The
button code detects an entry error and sends the page back to the
user. This all works.

However, if the user presses the Back button at this point, we go back
and all the form values are cleared. I've been all over the web
searching for a solution and all I can find is to either disable the
back button or clear the history so Back won't go back.

I can't get either of these to work either. I've tried adding the
javascript to the top of the body of the page:

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

I've tried adding this to the Page_Load event:

Response.Cache.SetCacheability(HttpCacheability.No Cache)

Yet I can still use the back button to go back to a blank page.

What's the solution to this problem?

Thanks!

Nov 19 '05 #8
As per advice I've tried this in the Page_Load:

Response.AppendHeader("Pragma", "no-cache")
Response.AppendHeader("Cache-Control", "no-store")
Response.AppendHeader("Expires", "-1")

And this:

Response.Expires = 0
Response.Cache.SetNoStore()
Response.AppendHeader("Pragma", "no-cache")

Same result, back button still takes me Back to an unfilled page.

On Wed, 16 Feb 2005 09:50:00 -0500, Tom wilson <ye*******@nospam.com>
wrote:
I can't believe this is such an impossibility...

I have an asp.net page. It accepts data through on form fields and
includes a submit button. The page loads up and you fill out some
stuff. The submit button posts the page back to the server. The
button code detects an entry error and sends the page back to the
user. This all works.

However, if the user presses the Back button at this point, we go back
and all the form values are cleared. I've been all over the web
searching for a solution and all I can find is to either disable the
back button or clear the history so Back won't go back.

I can't get either of these to work either. I've tried adding the
javascript to the top of the body of the page:

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

I've tried adding this to the Page_Load event:

Response.Cache.SetCacheability(HttpCacheability.N oCache)

Yet I can still use the back button to go back to a blank page.

What's the solution to this problem?

Thanks!


Nov 19 '05 #9
I now see you want the *opposite* of what I replied.

See
http://asp.net.do/test2/test3.aspx

That page returns the form's values when you hit the back button.
That is the *default* mode of operation for ASP.NET.

If you do *not* want values returned, then do *not*
introduce any code to force not-caching of the page.

What you want is for the page to *be* cached.

test3.aspx:
========
<%@ Page Language="VB" %>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
&nbsp;<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
</p>
<p>
&nbsp;<asp:Button id="Button1" runat="server"
Text="Button"></asp:Button>
</p>
</form>
</body>
</html>
============


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
=====================

"Tom wilson" <ye*******@nospam.com> wrote in message
news:h7********************************@4ax.com...
This page can have possibly hundreds of dynamically generated controls
on it, which is why I can't lose the data with a back click. I'd have
to dynamically create an unknown number of different arrays to store
the data, possibly tons of it. This is such a basic thing to do, I
don't understand why it's completely impossible without writing reams
of code to maintain the state of the pages. I thought that's what
asp.net did inherently:

http://www.w3schools.com/aspnet/aspnet_viewstate.asp

"When a form is submitted in classic ASP, all form values are cleared.
Suppose you have submitted a form with a lot of information and the
server comes back with an error. You will have to go back to the form
and correct the information. You click the back button, and what
happens.......ALL form values are CLEARED, and you will have to start
all over again! The site did not maintain your ViewState.

When a form is submitted in ASP .NET, the form reappears in the
browser window together with all form values. How come? This is
because ASP .NET maintains your ViewState. The ViewState indicates the
status of the page when submitted to the server. The status is defined
through a hidden field placed on each page with a <form
runat="server"> control. "

I don't get why the vewstate is not maintained in this example when
the above seems to imply that this is a very basic and default
behavior of asp.net pages.

Go to any site with an online application form like for a credit card.
They never have to disable the back button or post huge messages about
"Do not hit back!!!" all over the place...

Why can't I do that here?

On Wed, 16 Feb 2005 10:51:02 -0500, "Bob Barrows [MVP]"
<re******@NOyahoo.SPAMcom> wrote:
Tom wilson wrote:
I can't believe this is such an impossibility...

<snip of description of by-design behavior>

I would consider putting the form values into session upon submission.
Then
add code to page_load to check the session and load the values from
session
into the form elements if they exist. You'll need to work out some
details,
when to clear the session vars, preventing duplicate data processing, etc.

Bob Barrows

Nov 19 '05 #10
re:
If you do *not* want values returned, then do *not*
introduce any code to force not-caching of the page.
Aargh!

That should be :

If you *do* want values returned, then do *not*
introduce any code to force no-caching of the page.

What you want is for the page to *be* cached.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
=====================

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:Oq**************@TK2MSFTNGP12.phx.gbl...I now see you want the *opposite* of what I replied.

See
http://asp.net.do/test2/test3.aspx

That page returns the form's values when you hit the back button.
That is the *default* mode of operation for ASP.NET.

If you do *not* want values returned, then do *not*
introduce any code to force not-caching of the page.

What you want is for the page to *be* cached.

test3.aspx:
========
<%@ Page Language="VB" %>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
&nbsp;<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
</p>
<p>
&nbsp;<asp:Button id="Button1" runat="server"
Text="Button"></asp:Button>
</p>
</form>
</body>
</html>
============


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
=====================

"Tom wilson" <ye*******@nospam.com> wrote in message
news:h7********************************@4ax.com...
This page can have possibly hundreds of dynamically generated controls
on it, which is why I can't lose the data with a back click. I'd have
to dynamically create an unknown number of different arrays to store
the data, possibly tons of it. This is such a basic thing to do, I
don't understand why it's completely impossible without writing reams
of code to maintain the state of the pages. I thought that's what
asp.net did inherently:

http://www.w3schools.com/aspnet/aspnet_viewstate.asp

"When a form is submitted in classic ASP, all form values are cleared.
Suppose you have submitted a form with a lot of information and the
server comes back with an error. You will have to go back to the form
and correct the information. You click the back button, and what
happens.......ALL form values are CLEARED, and you will have to start
all over again! The site did not maintain your ViewState.

When a form is submitted in ASP .NET, the form reappears in the
browser window together with all form values. How come? This is
because ASP .NET maintains your ViewState. The ViewState indicates the
status of the page when submitted to the server. The status is defined
through a hidden field placed on each page with a <form
runat="server"> control. "

I don't get why the vewstate is not maintained in this example when
the above seems to imply that this is a very basic and default
behavior of asp.net pages.

Go to any site with an online application form like for a credit card.
They never have to disable the back button or post huge messages about
"Do not hit back!!!" all over the place...

Why can't I do that here?

On Wed, 16 Feb 2005 10:51:02 -0500, "Bob Barrows [MVP]"
<re******@NOyahoo.SPAMcom> wrote:
Tom wilson wrote:
I can't believe this is such an impossibility...

<snip of description of by-design behavior>

I would consider putting the form values into session upon submission.
Then
add code to page_load to check the session and load the values from
session
into the form elements if they exist. You'll need to work out some
details,
when to clear the session vars, preventing duplicate data processing,
etc.

Bob Barrows


Nov 19 '05 #11
Thanks for the reply.

Actually, that's the opposite. I need the value to remain.

Imagine this as an online credit app. I fill out my name and for some
reason it's wrong. I go Back to correct it and the field is empty.

Now imagine this as a page with hundreds of textboxes, radios, etc.
You take 30 minutes to fill it out and submit it. The server says
there's an error and you hit Back.

Everything you did for the last 30 minutes is gone in one innocent
button click. Every online web form I've seen will maintain the data.
Why won't this?

(thx!!!)

On Wed, 16 Feb 2005 12:05:44 -0400, "Juan T. Llibre"
<no***********@nowhere.com> wrote:
Hi, Tom.

I made a very simple test page,
which you can test at http://asp.net.do/test2/test2.aspx

It only has one textbox, but should work the same no
matter how many text fields you have on the page.

Check it out, and write something in the textbox.
Then, hit your browser's back button.

The text in the texbox disappears, whcih I
believe is the behavior you want, isn't it ?

If not, please let me know the behavior you want.

Source code :
test2.aspx:
=======
<%@ Page Language="VB" %>
<%@ OutputCache Location="None" %>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
</p>
</form>
</body>
</html>
============


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
=====================

"Tom wilson" <ye*******@nospam.com> wrote in message
news:ma********************************@4ax.com.. .
You were right!!! It made no difference. :)

Thanks tho...

On Wed, 16 Feb 2005 11:07:13 -0400, "Juan T. Llibre"
<no***********@nowhere.com> wrote:
I suppose it wouldn't hurt to try :

<%@ OutputCache Location="None" %>

No guarantees, though.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
=====================

"Tom wilson" <ye*******@nospam.com> wrote in message
news:or********************************@4ax.com ...
I can't believe this is such an impossibility...

I have an asp.net page. It accepts data through on form fields and
includes a submit button. The page loads up and you fill out some
stuff. The submit button posts the page back to the server. The
button code detects an entry error and sends the page back to the
user. This all works.

However, if the user presses the Back button at this point, we go back
and all the form values are cleared. I've been all over the web
searching for a solution and all I can find is to either disable the
back button or clear the history so Back won't go back.

I can't get either of these to work either. I've tried adding the
javascript to the top of the body of the page:

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

I've tried adding this to the Page_Load event:

Response.Cache.SetCacheability(HttpCacheability.No Cache)

Yet I can still use the back button to go back to a blank page.

What's the solution to this problem?

Thanks!


Nov 19 '05 #12
AHA!!! Yours works!

So I copied the source below, went into VS.Net and created a new
webform. I basically pasted everything below into the form.

The form loads.
I fill out the textbox and hit submit
Click Back, the textbox is empty.

Yet your link below does the opposite.

Now I'm really confused. Why would your code work on your server but
not mine?

">That is the *default* mode of operation for ASP.NET."

That's what I thought but I can't demonstrate this behavior.

(Thanks!!!)

On Wed, 16 Feb 2005 12:15:36 -0400, "Juan T. Llibre"
<no***********@nowhere.com> wrote:
I now see you want the *opposite* of what I replied.

See
http://asp.net.do/test2/test3.aspx

That page returns the form's values when you hit the back button.
That is the *default* mode of operation for ASP.NET.

If you do *not* want values returned, then do *not*
introduce any code to force not-caching of the page.

What you want is for the page to *be* cached.

test3.aspx:
========
<%@ Page Language="VB" %>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
&nbsp;<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
</p>
<p>
&nbsp;<asp:Button id="Button1" runat="server"
Text="Button"></asp:Button>
</p>
</form>
</body>
</html>
============


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
=====================

"Tom wilson" <ye*******@nospam.com> wrote in message
news:h7********************************@4ax.com.. .
This page can have possibly hundreds of dynamically generated controls
on it, which is why I can't lose the data with a back click. I'd have
to dynamically create an unknown number of different arrays to store
the data, possibly tons of it. This is such a basic thing to do, I
don't understand why it's completely impossible without writing reams
of code to maintain the state of the pages. I thought that's what
asp.net did inherently:

http://www.w3schools.com/aspnet/aspnet_viewstate.asp

"When a form is submitted in classic ASP, all form values are cleared.
Suppose you have submitted a form with a lot of information and the
server comes back with an error. You will have to go back to the form
and correct the information. You click the back button, and what
happens.......ALL form values are CLEARED, and you will have to start
all over again! The site did not maintain your ViewState.

When a form is submitted in ASP .NET, the form reappears in the
browser window together with all form values. How come? This is
because ASP .NET maintains your ViewState. The ViewState indicates the
status of the page when submitted to the server. The status is defined
through a hidden field placed on each page with a <form
runat="server"> control. "

I don't get why the vewstate is not maintained in this example when
the above seems to imply that this is a very basic and default
behavior of asp.net pages.

Go to any site with an online application form like for a credit card.
They never have to disable the back button or post huge messages about
"Do not hit back!!!" all over the place...

Why can't I do that here?

On Wed, 16 Feb 2005 10:51:02 -0500, "Bob Barrows [MVP]"
<re******@NOyahoo.SPAMcom> wrote:
Tom wilson wrote:
I can't believe this is such an impossibility...

<snip of description of by-design behavior>

I would consider putting the form values into session upon submission.
Then
add code to page_load to check the session and load the values from
session
into the form elements if they exist. You'll need to work out some
details,
when to clear the session vars, preventing duplicate data processing, etc.

Bob Barrows


Nov 19 '05 #13
On 16 Feb 2005, Tom wilson <ye*******@nospam.com> postulated in
news:kp********************************@4ax.com:
I've also tried this method:

<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">

I can use the back button all I want to return to blank pages.


Wait a minute.... you are NOT submitting the page, right?

So how could you cache it at the server?

The page lives in the Browser, not on the Server. The Server hasn't
seen the header returned by the Response message (sent from Browser
to Server when the user hits Submit).

This is a browser issue....not a server issue.

There are plugins available that help browsers maintain form values
across pages which you can recommend for your users. There may be
something you can do with IE, but I'm not much of a document object
model guy. Try the IE forum?

-- ipgrunt

Nov 19 '05 #14
If you wish the content to persist why are you setting it to expire
immediately?

MattC
"Tom wilson" <ye*******@nospam.com> wrote in message
news:56********************************@4ax.com...
Thanks for the reply.

Actually, that's the opposite. I need the value to remain.

Imagine this as an online credit app. I fill out my name and for some
reason it's wrong. I go Back to correct it and the field is empty.

Now imagine this as a page with hundreds of textboxes, radios, etc.
You take 30 minutes to fill it out and submit it. The server says
there's an error and you hit Back.

Everything you did for the last 30 minutes is gone in one innocent
button click. Every online web form I've seen will maintain the data.
Why won't this?

(thx!!!)

On Wed, 16 Feb 2005 12:05:44 -0400, "Juan T. Llibre"
<no***********@nowhere.com> wrote:
Hi, Tom.

I made a very simple test page,
which you can test at http://asp.net.do/test2/test2.aspx

It only has one textbox, but should work the same no
matter how many text fields you have on the page.

Check it out, and write something in the textbox.
Then, hit your browser's back button.

The text in the texbox disappears, whcih I
believe is the behavior you want, isn't it ?

If not, please let me know the behavior you want.

Source code :
test2.aspx:
=======
<%@ Page Language="VB" %>
<%@ OutputCache Location="None" %>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
</p>
</form>
</body>
</html>
============


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
=====================

"Tom wilson" <ye*******@nospam.com> wrote in message
news:ma********************************@4ax.com. ..
You were right!!! It made no difference. :)

Thanks tho...

On Wed, 16 Feb 2005 11:07:13 -0400, "Juan T. Llibre"
<no***********@nowhere.com> wrote:

I suppose it wouldn't hurt to try :

<%@ OutputCache Location="None" %>

No guarantees, though.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
=====================

"Tom wilson" <ye*******@nospam.com> wrote in message
news:or********************************@4ax.co m...
>I can't believe this is such an impossibility...
>
> I have an asp.net page. It accepts data through on form fields and
> includes a submit button. The page loads up and you fill out some
> stuff. The submit button posts the page back to the server. The
> button code detects an entry error and sends the page back to the
> user. This all works.
>
> However, if the user presses the Back button at this point, we go back
> and all the form values are cleared. I've been all over the web
> searching for a solution and all I can find is to either disable the
> back button or clear the history so Back won't go back.
>
> I can't get either of these to work either. I've tried adding the
> javascript to the top of the body of the page:
>
> <%
> Response.Buffer = True
> Response.ExpiresAbsolute = DateTime.Now.AddDays(-1)
> Response.Expires = 0
> Response.CacheControl = "no-cache"
> %>
>
> I've tried adding this to the Page_Load event:
>
> Response.Cache.SetCacheability(HttpCacheability.No Cache)
>
> Yet I can still use the back button to go back to a blank page.
>
> What's the solution to this problem?
>
> Thanks!

Nov 19 '05 #15
As far as I know I do, there's a submit button (with no codeback code)
that is clicked to cause a postback. If the page lives in the
browser, why would the form data be cleared when the back button is
clicked ? (after the submit button is clicked)
On 16 Feb 2005 16:39:19 GMT, IPGrunt <me@privacy.net> wrote:
On 16 Feb 2005, Tom wilson <ye*******@nospam.com> postulated in
news:kp********************************@4ax.com :
I've also tried this method:

<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">

I can use the back button all I want to return to blank pages.


Wait a minute.... you are NOT submitting the page, right?

So how could you cache it at the server?

The page lives in the Browser, not on the Server. The Server hasn't
seen the header returned by the Response message (sent from Browser
to Server when the user hits Submit).

This is a browser issue....not a server issue.

There are plugins available that help browsers maintain form values
across pages which you can recommend for your users. There may be
something you can do with IE, but I'm not much of a document object
model guy. Try the IE forum?

-- ipgrunt


Nov 19 '05 #16
remove this

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

Response.AppendHeader("Pragma", "no-cache")
Response.AppendHeader("Cache-Control", "no-store")
Response.AppendHeader("Expires", "-1")

you are setting the page content to expire immediately so your browser is no
storing the content in its _local_ cache.

Also, pressing the back button does _not_ constitute a postback so there is
no notion of ViewState.

MattC

"Tom wilson" <ye*******@nospam.com> wrote in message
news:8t********************************@4ax.com...
As per advice I've tried this in the Page_Load:

Response.AppendHeader("Pragma", "no-cache")
Response.AppendHeader("Cache-Control", "no-store")
Response.AppendHeader("Expires", "-1")

And this:

Response.Expires = 0
Response.Cache.SetNoStore()
Response.AppendHeader("Pragma", "no-cache")

Same result, back button still takes me Back to an unfilled page.

On Wed, 16 Feb 2005 09:50:00 -0500, Tom wilson <ye*******@nospam.com>
wrote:
I can't believe this is such an impossibility...

I have an asp.net page. It accepts data through on form fields and
includes a submit button. The page loads up and you fill out some
stuff. The submit button posts the page back to the server. The
button code detects an entry error and sends the page back to the
user. This all works.

However, if the user presses the Back button at this point, we go back
and all the form values are cleared. I've been all over the web
searching for a solution and all I can find is to either disable the
back button or clear the history so Back won't go back.

I can't get either of these to work either. I've tried adding the
javascript to the top of the body of the page:

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

I've tried adding this to the Page_Load event:

Response.Cache.SetCacheability(HttpCacheability. NoCache)

Yet I can still use the back button to go back to a blank page.

What's the solution to this problem?

Thanks!

Nov 19 '05 #17
I'm trying, as one solution, to disable the back button. Since that's
not feasable, I'm attempting to clear the hitory so one can't 'go
back'. But I cna't get that to work either, out of 5 different
methods.
On Wed, 16 Feb 2005 16:45:37 -0000, "MattC" <m@m.com> wrote:
If you wish the content to persist why are you setting it to expire
immediately?

MattC
"Tom wilson" <ye*******@nospam.com> wrote in message
news:56********************************@4ax.com.. .
Thanks for the reply.

Actually, that's the opposite. I need the value to remain.

Imagine this as an online credit app. I fill out my name and for some
reason it's wrong. I go Back to correct it and the field is empty.

Now imagine this as a page with hundreds of textboxes, radios, etc.
You take 30 minutes to fill it out and submit it. The server says
there's an error and you hit Back.

Everything you did for the last 30 minutes is gone in one innocent
button click. Every online web form I've seen will maintain the data.
Why won't this?

(thx!!!)

On Wed, 16 Feb 2005 12:05:44 -0400, "Juan T. Llibre"
<no***********@nowhere.com> wrote:
Hi, Tom.

I made a very simple test page,
which you can test at http://asp.net.do/test2/test2.aspx

It only has one textbox, but should work the same no
matter how many text fields you have on the page.

Check it out, and write something in the textbox.
Then, hit your browser's back button.

The text in the texbox disappears, whcih I
believe is the behavior you want, isn't it ?

If not, please let me know the behavior you want.

Source code :
test2.aspx:
=======
<%@ Page Language="VB" %>
<%@ OutputCache Location="None" %>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
</p>
</form>
</body>
</html>
============


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
=====================

"Tom wilson" <ye*******@nospam.com> wrote in message
news:ma********************************@4ax.com ...
You were right!!! It made no difference. :)

Thanks tho...

On Wed, 16 Feb 2005 11:07:13 -0400, "Juan T. Llibre"
<no***********@nowhere.com> wrote:

>I suppose it wouldn't hurt to try :
>
><%@ OutputCache Location="None" %>
>
>No guarantees, though.
>
>
>
>Juan T. Llibre
>ASP.NET MVP
>http://asp.net.do/foros/
>Foros de ASP.NET en Español
>=====================
>
>"Tom wilson" <ye*******@nospam.com> wrote in message
>news:or********************************@4ax.c om...
>>I can't believe this is such an impossibility...
>>
>> I have an asp.net page. It accepts data through on form fields and
>> includes a submit button. The page loads up and you fill out some
>> stuff. The submit button posts the page back to the server. The
>> button code detects an entry error and sends the page back to the
>> user. This all works.
>>
>> However, if the user presses the Back button at this point, we go back
>> and all the form values are cleared. I've been all over the web
>> searching for a solution and all I can find is to either disable the
>> back button or clear the history so Back won't go back.
>>
>> I can't get either of these to work either. I've tried adding the
>> javascript to the top of the body of the page:
>>
>> <%
>> Response.Buffer = True
>> Response.ExpiresAbsolute = DateTime.Now.AddDays(-1)
>> Response.Expires = 0
>> Response.CacheControl = "no-cache"
>> %>
>>
>> I've tried adding this to the Page_Load event:
>>
>> Response.Cache.SetCacheability(HttpCacheability.No Cache)
>>
>> Yet I can still use the back button to go back to a blank page.
>>
>> What's the solution to this problem?
>>
>> Thanks!
>


Nov 19 '05 #18
Ok, I removed all forms of cache or history stuff.

I select a radio, click submit.
I click back and the radio is de-selected.
Also, pressing the back button does _not_ constitute a postback so there is
no notion of ViewState.
Then what does this mean?:

"When a form is submitted in classic ASP, all form values are cleared.
Suppose you have submitted a form with a lot of information and the
server comes back with an error. You will have to go back to the form
and correct the information. You click the back button, and what
happens.......ALL form values are CLEARED, and you will have to start
all over again! The site did not maintain your ViewState.

When a form is submitted in ASP .NET, the form reappears in the
browser window together with all form values. How come? ****This is
because ASP .NET maintains your ViewState. The ViewState indicates the
status of the page when submitted to the server.**** The status is
defined through a hidden field placed on each page with a <form
runat="server"> control. "

So when I click the submit button the page is sent to the server (to
do nothing really in this case). Why is the viewstate not being
maintained?

Thanks...
On Wed, 16 Feb 2005 16:49:33 -0000, "MattC" <m@m.com> wrote:
remove this

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

Response.AppendHeader("Pragma", "no-cache")
Response.AppendHeader("Cache-Control", "no-store")
Response.AppendHeader("Expires", "-1")

you are setting the page content to expire immediately so your browser is no
storing the content in its _local_ cache.

Also, pressing the back button does _not_ constitute a postback so there is
no notion of ViewState.

MattC

"Tom wilson" <ye*******@nospam.com> wrote in message
news:8t********************************@4ax.com.. .
As per advice I've tried this in the Page_Load:

Response.AppendHeader("Pragma", "no-cache")
Response.AppendHeader("Cache-Control", "no-store")
Response.AppendHeader("Expires", "-1")

And this:

Response.Expires = 0
Response.Cache.SetNoStore()
Response.AppendHeader("Pragma", "no-cache")

Same result, back button still takes me Back to an unfilled page.

On Wed, 16 Feb 2005 09:50:00 -0500, Tom wilson <ye*******@nospam.com>
wrote:
I can't believe this is such an impossibility...

I have an asp.net page. It accepts data through on form fields and
includes a submit button. The page loads up and you fill out some
stuff. The submit button posts the page back to the server. The
button code detects an entry error and sends the page back to the
user. This all works.

However, if the user presses the Back button at this point, we go back
and all the form values are cleared. I've been all over the web
searching for a solution and all I can find is to either disable the
back button or clear the history so Back won't go back.

I can't get either of these to work either. I've tried adding the
javascript to the top of the body of the page:

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

I've tried adding this to the Page_Load event:

Response.Cache.SetCacheability(HttpCacheability .NoCache)

Yet I can still use the back button to go back to a blank page.

What's the solution to this problem?

Thanks!


Nov 19 '05 #19
On 16 Feb 2005, Tom wilson <ye*******@nospam.com> postulated in
news:rb********************************@4ax.com:
As far as I know I do, there's a submit button (with no codeback code) that is clicked to cause a postback. If the page lives in the
browser, why would the form data be cleared when the back button is
clicked ? (after the submit button is clicked)
On 16 Feb 2005 16:39:19 GMT, IPGrunt <me@privacy.net> wrote:
On 16 Feb 2005, Tom wilson <ye*******@nospam.com> postulated in
news:kp********************************@4ax.co m:
I've also tried this method:

<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">

I can use the back button all I want to return to blank pages.


Wait a minute.... you are NOT submitting the page, right?

So how could you cache it at the server?

The page lives in the Browser, not on the Server. The Server hasn't
seen the header returned by the Response message (sent from Browser
to Server when the user hits Submit).

This is a browser issue....not a server issue.

There are plugins available that help browsers maintain form values
across pages which you can recommend for your users. There may be
something you can do with IE, but I'm not much of a document object
model guy. Try the IE forum?

-- ipgrunt


In my initial post to you, I thought you had not submitted the page. I
wanted to be sure that you understood the process.

By the way, why is there no code behind the submit button?

So, here we have two cases:

If the page, form and controls are set to use viewstate, then after
postback, those values will persist.

If the page is not submitted, ie, no postback, there's not gonna be any
viewstate created.

These are the two states to consider BEFORE the back button gets
clicked.

You can test, to see which state you're in--use the debugger to examine
viewstate. There are other techniques...this is a digression, but I
read a nice article recently that described how viewstate is encoded. I
can't recall the URL now, but if you search I'll bet you find it. This
way you could even write some of those values out to screen or a file
to convince yourself they are there.

If you have viewstate, then when you go back, and return, I wonder if
your controls are being reinitialized. This is what Juan was referring
to.

Again, use the debugger and write some test code.
-- ipgrunt
Nov 19 '05 #20
there are two senerios with the back button

1) the server did not set the page expired. when the back button is hit the
browser loads the previous page from its local disk cache with the textboxes
having the value the user entered before navigating away.

2) the server marked the page as expired. when the browser fetches the page
from the cache, it asks the server for a new copy. (you can tell if your in
this case by setting a breakpoint on the page and seeing the back button
fires it). the browser rerequests the page, it the textboxes have whatever
value your page puts in them. normally you'd store the values in a session,
and update the page if required.
-- bruce (sqlwork.com)

"Tom wilson" <ye*******@nospam.com> wrote in message
news:or********************************@4ax.com...
| I can't believe this is such an impossibility...
|
| I have an asp.net page. It accepts data through on form fields and
| includes a submit button. The page loads up and you fill out some
| stuff. The submit button posts the page back to the server. The
| button code detects an entry error and sends the page back to the
| user. This all works.
|
| However, if the user presses the Back button at this point, we go back
| and all the form values are cleared. I've been all over the web
| searching for a solution and all I can find is to either disable the
| back button or clear the history so Back won't go back.
|
| I can't get either of these to work either. I've tried adding the
| javascript to the top of the body of the page:
|
| <%
| Response.Buffer = True
| Response.ExpiresAbsolute = DateTime.Now.AddDays(-1)
| Response.Expires = 0
| Response.CacheControl = "no-cache"
| %>
|
| I've tried adding this to the Page_Load event:
|
| Response.Cache.SetCacheability(HttpCacheability.No Cache)
|
| Yet I can still use the back button to go back to a blank page.
|
| What's the solution to this problem?
|
| Thanks!
|
Nov 19 '05 #21
Ok, if you have expired the page then clicking the back button will cause
the browser to ask for the page, from scratch, as the content of the page
expired so did the viewstate stored in the page. AS there is no viewstate
your controls are empty.

It would seem that the page is expiring so the browser is asking for a new
version of the page.

MattC

"Tom wilson" <ye*******@nospam.com> wrote in message
news:bg********************************@4ax.com...
Ok, I removed all forms of cache or history stuff.

I select a radio, click submit.
I click back and the radio is de-selected.
Also, pressing the back button does _not_ constitute a postback so there
is
no notion of ViewState.


Then what does this mean?:

"When a form is submitted in classic ASP, all form values are cleared.
Suppose you have submitted a form with a lot of information and the
server comes back with an error. You will have to go back to the form
and correct the information. You click the back button, and what
happens.......ALL form values are CLEARED, and you will have to start
all over again! The site did not maintain your ViewState.

When a form is submitted in ASP .NET, the form reappears in the
browser window together with all form values. How come? ****This is
because ASP .NET maintains your ViewState. The ViewState indicates the
status of the page when submitted to the server.**** The status is
defined through a hidden field placed on each page with a <form
runat="server"> control. "

So when I click the submit button the page is sent to the server (to
do nothing really in this case). Why is the viewstate not being
maintained?

Thanks...
On Wed, 16 Feb 2005 16:49:33 -0000, "MattC" <m@m.com> wrote:
remove this

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

Response.AppendHeader("Pragma", "no-cache")
Response.AppendHeader("Cache-Control", "no-store")
Response.AppendHeader("Expires", "-1")

you are setting the page content to expire immediately so your browser is
no
storing the content in its _local_ cache.

Also, pressing the back button does _not_ constitute a postback so there
is
no notion of ViewState.

MattC

"Tom wilson" <ye*******@nospam.com> wrote in message
news:8t********************************@4ax.com. ..
As per advice I've tried this in the Page_Load:

Response.AppendHeader("Pragma", "no-cache")
Response.AppendHeader("Cache-Control", "no-store")
Response.AppendHeader("Expires", "-1")

And this:

Response.Expires = 0
Response.Cache.SetNoStore()
Response.AppendHeader("Pragma", "no-cache")

Same result, back button still takes me Back to an unfilled page.

On Wed, 16 Feb 2005 09:50:00 -0500, Tom wilson <ye*******@nospam.com>
wrote:

I can't believe this is such an impossibility...

I have an asp.net page. It accepts data through on form fields and
includes a submit button. The page loads up and you fill out some
stuff. The submit button posts the page back to the server. The
button code detects an entry error and sends the page back to the
user. This all works.

However, if the user presses the Back button at this point, we go back
and all the form values are cleared. I've been all over the web
searching for a solution and all I can find is to either disable the
back button or clear the history so Back won't go back.

I can't get either of these to work either. I've tried adding the
javascript to the top of the body of the page:

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

I've tried adding this to the Page_Load event:

Response.Cache.SetCacheability(HttpCacheabilit y.NoCache)

Yet I can still use the back button to go back to a blank page.

What's the solution to this problem?

Thanks!

Nov 19 '05 #22
Debugger? I can never get that to work. I assume because I need to
install VS.Net on the server. Is it wise to install VS.Net on a live
production server? The thought makes me a bit nervous.

On 16 Feb 2005 17:16:24 GMT, IPGrunt <me@privacy.net> wrote:
Again, use the debugger and write some test code.


Nov 19 '05 #23
On 16 Feb 2005, Tom wilson <ye*******@nospam.com> postulated in
news:ke********************************@4ax.com:
Debugger? I can never get that to work. I assume because I need to install VS.Net on the server. Is it wise to install VS.Net on a live production server? The thought makes me a bit nervous.

On 16 Feb 2005 17:16:24 GMT, IPGrunt <me@privacy.net> wrote:
Again, use the debugger and write some test code.


Man, using the debugger is half of what .NET is all about in
increasing programmer productivity. If you're not using the debugger,
you're flailing in the dark (which you are).

Can't you load the framework on your workstation?

Theoretically you shouldn't debug on a live server, but you CAN make
a development site there that users won't see and work that way. Make
sure you're NOT using the server side debugger, as you can stop the
entire IIS processing (or maybe not with ASP.NET... I really haven't
tried).

I gotta go to work. Do yourself a favor and get a debugging setup
working. You'll save loads of time.

-- ipgrunt

Nov 19 '05 #24
That makes sense, and is likely. but of all the trillions of things
that could expire the page, where to look first?
On Wed, 16 Feb 2005 17:32:49 -0000, "MattC" <m@m.com> wrote:
Ok, if you have expired the page then clicking the back button will cause
the browser to ask for the page, from scratch, as the content of the page
expired so did the viewstate stored in the page. AS there is no viewstate
your controls are empty.

It would seem that the page is expiring so the browser is asking for a new
version of the page.

MattC

"Tom wilson" <ye*******@nospam.com> wrote in message
news:bg********************************@4ax.com.. .
Ok, I removed all forms of cache or history stuff.

I select a radio, click submit.
I click back and the radio is de-selected.
Also, pressing the back button does _not_ constitute a postback so there
is
no notion of ViewState.


Then what does this mean?:

"When a form is submitted in classic ASP, all form values are cleared.
Suppose you have submitted a form with a lot of information and the
server comes back with an error. You will have to go back to the form
and correct the information. You click the back button, and what
happens.......ALL form values are CLEARED, and you will have to start
all over again! The site did not maintain your ViewState.

When a form is submitted in ASP .NET, the form reappears in the
browser window together with all form values. How come? ****This is
because ASP .NET maintains your ViewState. The ViewState indicates the
status of the page when submitted to the server.**** The status is
defined through a hidden field placed on each page with a <form
runat="server"> control. "

So when I click the submit button the page is sent to the server (to
do nothing really in this case). Why is the viewstate not being
maintained?

Thanks...
On Wed, 16 Feb 2005 16:49:33 -0000, "MattC" <m@m.com> wrote:
remove this

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

Response.AppendHeader("Pragma", "no-cache")
Response.AppendHeader("Cache-Control", "no-store")
Response.AppendHeader("Expires", "-1")

you are setting the page content to expire immediately so your browser is
no
storing the content in its _local_ cache.

Also, pressing the back button does _not_ constitute a postback so there
is
no notion of ViewState.

MattC

"Tom wilson" <ye*******@nospam.com> wrote in message
news:8t********************************@4ax.com ...
As per advice I've tried this in the Page_Load:

Response.AppendHeader("Pragma", "no-cache")
Response.AppendHeader("Cache-Control", "no-store")
Response.AppendHeader("Expires", "-1")

And this:

Response.Expires = 0
Response.Cache.SetNoStore()
Response.AppendHeader("Pragma", "no-cache")

Same result, back button still takes me Back to an unfilled page.

On Wed, 16 Feb 2005 09:50:00 -0500, Tom wilson <ye*******@nospam.com>
wrote:

>I can't believe this is such an impossibility...
>
>I have an asp.net page. It accepts data through on form fields and
>includes a submit button. The page loads up and you fill out some
>stuff. The submit button posts the page back to the server. The
>button code detects an entry error and sends the page back to the
>user. This all works.
>
>However, if the user presses the Back button at this point, we go back
>and all the form values are cleared. I've been all over the web
>searching for a solution and all I can find is to either disable the
>back button or clear the history so Back won't go back.
>
>I can't get either of these to work either. I've tried adding the
>javascript to the top of the body of the page:
>
><%
> Response.Buffer = True
> Response.ExpiresAbsolute = DateTime.Now.AddDays(-1)
> Response.Expires = 0
> Response.CacheControl = "no-cache"
>%>
>
>I've tried adding this to the Page_Load event:
>
>Response.Cache.SetCacheability(HttpCacheabili ty.NoCache)
>
>Yet I can still use the back button to go back to a blank page.
>
>What's the solution to this problem?
>
>Thanks!


Nov 19 '05 #25
I've done a test using a time field. The page, when using the Back
button, is retrieved from IE's cache. It's not a fresh copy of the
page from the server. The latter would explain everything.

So the server marked the page as expired? Where ? How? How to stop
it?

Thanks...

On Wed, 16 Feb 2005 09:16:13 -0800, "bruce barker"
<no***********@safeco.com> wrote:
there are two senerios with the back button

1) the server did not set the page expired. when the back button is hit the
browser loads the previous page from its local disk cache with the textboxes
having the value the user entered before navigating away.

2) the server marked the page as expired. when the browser fetches the page
from the cache, it asks the server for a new copy. (you can tell if your in
this case by setting a breakpoint on the page and seeing the back button
fires it). the browser rerequests the page, it the textboxes have whatever
value your page puts in them. normally you'd store the values in a session,
and update the page if required.
-- bruce (sqlwork.com)

"Tom wilson" <ye*******@nospam.com> wrote in message
news:or********************************@4ax.com.. .
| I can't believe this is such an impossibility...
|
| I have an asp.net page. It accepts data through on form fields and
| includes a submit button. The page loads up and you fill out some
| stuff. The submit button posts the page back to the server. The
| button code detects an entry error and sends the page back to the
| user. This all works.
|
| However, if the user presses the Back button at this point, we go back
| and all the form values are cleared. I've been all over the web
| searching for a solution and all I can find is to either disable the
| back button or clear the history so Back won't go back.
|
| I can't get either of these to work either. I've tried adding the
| javascript to the top of the body of the page:
|
| <%
| Response.Buffer = True
| Response.ExpiresAbsolute = DateTime.Now.AddDays(-1)
| Response.Expires = 0
| Response.CacheControl = "no-cache"
| %>
|
| I've tried adding this to the Page_Load event:
|
| Response.Cache.SetCacheability(HttpCacheability.No Cache)
|
| Yet I can still use the back button to go back to a blank page.
|
| What's the solution to this problem?
|
| Thanks!
|


Nov 19 '05 #26
Did you check the Internet Explorer -> Tools -> Internet Options -> Temporary
Internet Files -> Settings?

I have no problems with a standard .ASPX pages with Webcontrols (RadioButton
Group, TextBox etc.) and the browser Backbutton. When I use normal
HTML-controls then the fields are empty.

EXAMPLE:
<%@ Page language="c#" Codebehind="project.aspx.cs" AutoEventWireup="false"
Inherits="project.project" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>project</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 16px; POSITION:
absolute; TOP: 24px" runat="server"></asp:TextBox>
<asp:TextBox id="TextBox2" style="Z-INDEX: 102; LEFT: 16px; POSITION:
absolute; TOP: 56px" runat="server"></asp:TextBox>
<asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 16px; POSITION:
absolute; TOP: 88px" runat="server"
Text="Button"></asp:Button><INPUT style="Z-INDEX: 104; LEFT: 24px;
POSITION: absolute; TOP: 144px" type="text"><INPUT style="Z-INDEX: 105; LEFT:
24px; POSITION: absolute; TOP: 176px" type="text"><INPUT style="Z-INDEX: 106;
LEFT: 24px; POSITION: absolute; TOP: 208px" type="submit" value="Submit">
<asp:RadioButtonList id="RadioButtonList1" style="Z-INDEX: 107; LEFT:
240px; POSITION: absolute; TOP: 24px"
runat="server" Width="112px">
<asp:ListItem Value="Item 1">Item 1</asp:ListItem>
<asp:ListItem Value="Item 2">Item 2</asp:ListItem>
</asp:RadioButtonList>
</form>
</body>
</HTML>
Alexander Meeder
"Tom wilson" wrote:
I've done a test using a time field. The page, when using the Back
button, is retrieved from IE's cache. It's not a fresh copy of the
page from the server. The latter would explain everything.

So the server marked the page as expired? Where ? How? How to stop
it?

Thanks...

On Wed, 16 Feb 2005 09:16:13 -0800, "bruce barker"
<no***********@safeco.com> wrote:
there are two senerios with the back button

1) the server did not set the page expired. when the back button is hit the
browser loads the previous page from its local disk cache with the textboxes
having the value the user entered before navigating away.

2) the server marked the page as expired. when the browser fetches the page
from the cache, it asks the server for a new copy. (you can tell if your in
this case by setting a breakpoint on the page and seeing the back button
fires it). the browser rerequests the page, it the textboxes have whatever
value your page puts in them. normally you'd store the values in a session,
and update the page if required.
-- bruce (sqlwork.com)

"Tom wilson" <ye*******@nospam.com> wrote in message
news:or********************************@4ax.com.. .
| I can't believe this is such an impossibility...
|
| I have an asp.net page. It accepts data through on form fields and
| includes a submit button. The page loads up and you fill out some
| stuff. The submit button posts the page back to the server. The
| button code detects an entry error and sends the page back to the
| user. This all works.
|
| However, if the user presses the Back button at this point, we go back
| and all the form values are cleared. I've been all over the web
| searching for a solution and all I can find is to either disable the
| back button or clear the history so Back won't go back.
|
| I can't get either of these to work either. I've tried adding the
| javascript to the top of the body of the page:
|
| <%
| Response.Buffer = True
| Response.ExpiresAbsolute = DateTime.Now.AddDays(-1)
| Response.Expires = 0
| Response.CacheControl = "no-cache"
| %>
|
| I've tried adding this to the Page_Load event:
|
| Response.Cache.SetCacheability(HttpCacheability.No Cache)
|
| Yet I can still use the back button to go back to a blank page.
|
| What's the solution to this problem?
|
| Thanks!
|


Nov 19 '05 #27
Yes, it works for me too. I don't get it cause my pages don't work
with IE. Firefox and Netscape retain the values fine.

Thanks!
On Thu, 17 Feb 2005 04:59:02 -0800, "Alexander Meeder" <Alexander
Me****@discussions.microsoft.com> wrote:
Did you check the Internet Explorer -> Tools -> Internet Options -> Temporary
Internet Files -> Settings?

I have no problems with a standard .ASPX pages with Webcontrols (RadioButton
Group, TextBox etc.) and the browser Backbutton. When I use normal
HTML-controls then the fields are empty.

EXAMPLE:
<%@ Page language="c#" Codebehind="project.aspx.cs" AutoEventWireup="false"
Inherits="project.project" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>project</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 16px; POSITION:
absolute; TOP: 24px" runat="server"></asp:TextBox>
<asp:TextBox id="TextBox2" style="Z-INDEX: 102; LEFT: 16px; POSITION:
absolute; TOP: 56px" runat="server"></asp:TextBox>
<asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 16px; POSITION:
absolute; TOP: 88px" runat="server"
Text="Button"></asp:Button><INPUT style="Z-INDEX: 104; LEFT: 24px;
POSITION: absolute; TOP: 144px" type="text"><INPUT style="Z-INDEX: 105; LEFT:
24px; POSITION: absolute; TOP: 176px" type="text"><INPUT style="Z-INDEX: 106;
LEFT: 24px; POSITION: absolute; TOP: 208px" type="submit" value="Submit">
<asp:RadioButtonList id="RadioButtonList1" style="Z-INDEX: 107; LEFT:
240px; POSITION: absolute; TOP: 24px"
runat="server" Width="112px">
<asp:ListItem Value="Item 1">Item 1</asp:ListItem>
<asp:ListItem Value="Item 2">Item 2</asp:ListItem>
</asp:RadioButtonList>
</form>
</body>
</HTML>
Alexander Meeder
"Tom wilson" wrote:
I've done a test using a time field. The page, when using the Back
button, is retrieved from IE's cache. It's not a fresh copy of the
page from the server. The latter would explain everything.

So the server marked the page as expired? Where ? How? How to stop
it?

Thanks...

On Wed, 16 Feb 2005 09:16:13 -0800, "bruce barker"
<no***********@safeco.com> wrote:
>there are two senerios with the back button
>
>1) the server did not set the page expired. when the back button is hit the
>browser loads the previous page from its local disk cache with the textboxes
>having the value the user entered before navigating away.
>
>2) the server marked the page as expired. when the browser fetches the page
>from the cache, it asks the server for a new copy. (you can tell if your in
>this case by setting a breakpoint on the page and seeing the back button
>fires it). the browser rerequests the page, it the textboxes have whatever
>value your page puts in them. normally you'd store the values in a session,
>and update the page if required.
>
>
>-- bruce (sqlwork.com)
>
>
>
>"Tom wilson" <ye*******@nospam.com> wrote in message
>news:or********************************@4ax.com.. .
>| I can't believe this is such an impossibility...
>|
>| I have an asp.net page. It accepts data through on form fields and
>| includes a submit button. The page loads up and you fill out some
>| stuff. The submit button posts the page back to the server. The
>| button code detects an entry error and sends the page back to the
>| user. This all works.
>|
>| However, if the user presses the Back button at this point, we go back
>| and all the form values are cleared. I've been all over the web
>| searching for a solution and all I can find is to either disable the
>| back button or clear the history so Back won't go back.
>|
>| I can't get either of these to work either. I've tried adding the
>| javascript to the top of the body of the page:
>|
>| <%
>| Response.Buffer = True
>| Response.ExpiresAbsolute = DateTime.Now.AddDays(-1)
>| Response.Expires = 0
>| Response.CacheControl = "no-cache"
>| %>
>|
>| I've tried adding this to the Page_Load event:
>|
>| Response.Cache.SetCacheability(HttpCacheability.No Cache)
>|
>| Yet I can still use the back button to go back to a blank page.
>|
>| What's the solution to this problem?
>|
>| Thanks!
>|
>



Nov 19 '05 #28
Correct me if I'm wrong, but it sounds like, once you submit your page to the
server, your server app is returning some type of error page, requiring you
to go "back" to the form page to fix your errors. Have you tried simply
having the server bring the user right back to the form page, with some error
text up top, and all the field data maintained? Since you've posted it to the
server, the server has all your dymamic fields + all the field data entered,
so it can just regenerate the form page, with submitted values populated.

In this scenario, there's no need to push the Back button.

David Makogon

"Tom wilson" wrote:
This page can have possibly hundreds of dynamically generated controls
on it, which is why I can't lose the data with a back click. I'd have
to dynamically create an unknown number of different arrays to store
the data, possibly tons of it. This is such a basic thing to do, I
don't understand why it's completely impossible without writing reams
of code to maintain the state of the pages. I thought that's what
asp.net did inherently:

http://www.w3schools.com/aspnet/aspnet_viewstate.asp

"When a form is submitted in classic ASP, all form values are cleared.
Suppose you have submitted a form with a lot of information and the
server comes back with an error. You will have to go back to the form
and correct the information. You click the back button, and what
happens.......ALL form values are CLEARED, and you will have to start
all over again! The site did not maintain your ViewState.

When a form is submitted in ASP .NET, the form reappears in the
browser window together with all form values. How come? This is
because ASP .NET maintains your ViewState. The ViewState indicates the
status of the page when submitted to the server. The status is defined
through a hidden field placed on each page with a <form
runat="server"> control. "

I don't get why the vewstate is not maintained in this example when
the above seems to imply that this is a very basic and default
behavior of asp.net pages.

Go to any site with an online application form like for a credit card.
They never have to disable the back button or post huge messages about
"Do not hit back!!!" all over the place...

Why can't I do that here?

On Wed, 16 Feb 2005 10:51:02 -0500, "Bob Barrows [MVP]"
<re******@NOyahoo.SPAMcom> wrote:
Tom wilson wrote:
I can't believe this is such an impossibility...

<snip of description of by-design behavior>

I would consider putting the form values into session upon submission. Then
add code to page_load to check the session and load the values from session
into the form elements if they exist. You'll need to work out some details,
when to clear the session vars, preventing duplicate data processing, etc.

Bob Barrows


Nov 19 '05 #29
Abe
Here's what's happening (AFAIK):
When you click the submit button, it sounds like you are going to a new page
that tells the user that something went wrong...or am I not reading this
correctly? What you should be doing is keeping the user on the same page as
your dynamically created form and on submission of that form (postback), set
up some error strings and whatnot on the page to let the user know what they
need to correct. Now send the form page back to the user. This way you still
have your ViewState active and it will keep your form values populated. Well,
as long as you don't reset them on postback.

What you're seeing when you go to a new page and then hit the back button,
is the page that was saved in your browser's history. This page is a copy of
what that page looked like when it was last sent from the server. You're
seeing empty fields because that's what that page looked like when it was
last sent to the client from the server. Any interaction that the user did to
that form page will ultimately be lost because that was all done client side
and doesn't affect the copy in the browser's history. Now, if you posted back
that form page with error strings or something of the like, then after the
user fixed the errors and submitted the form again, and on the subsequent
page(a new different confirmation page maybe) the user would click the
browser's back button, they should see a copy of the form with the fields
filled in and the error strings still present. Exactly what was last sent
from the server to the client. If they clicked the back button again, they
would see the empty form page.

Now don't take this as 100% correct as it is late on a Friday afternoon, but
I hope this gives you some better direction.

"Tom wilson" wrote:
This page can have possibly hundreds of dynamically generated controls
on it, which is why I can't lose the data with a back click. I'd have
to dynamically create an unknown number of different arrays to store
the data, possibly tons of it. This is such a basic thing to do, I
don't understand why it's completely impossible without writing reams
of code to maintain the state of the pages. I thought that's what
asp.net did inherently:

http://www.w3schools.com/aspnet/aspnet_viewstate.asp

"When a form is submitted in classic ASP, all form values are cleared.
Suppose you have submitted a form with a lot of information and the
server comes back with an error. You will have to go back to the form
and correct the information. You click the back button, and what
happens.......ALL form values are CLEARED, and you will have to start
all over again! The site did not maintain your ViewState.

When a form is submitted in ASP .NET, the form reappears in the
browser window together with all form values. How come? This is
because ASP .NET maintains your ViewState. The ViewState indicates the
status of the page when submitted to the server. The status is defined
through a hidden field placed on each page with a <form
runat="server"> control. "

I don't get why the vewstate is not maintained in this example when
the above seems to imply that this is a very basic and default
behavior of asp.net pages.

Go to any site with an online application form like for a credit card.
They never have to disable the back button or post huge messages about
"Do not hit back!!!" all over the place...

Why can't I do that here?

On Wed, 16 Feb 2005 10:51:02 -0500, "Bob Barrows [MVP]"
<re******@NOyahoo.SPAMcom> wrote:
Tom wilson wrote:
I can't believe this is such an impossibility...

<snip of description of by-design behavior>

I would consider putting the form values into session upon submission. Then
add code to page_load to check the session and load the values from session
into the form elements if they exist. You'll need to work out some details,
when to clear the session vars, preventing duplicate data processing, etc.

Bob Barrows


Nov 19 '05 #30

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

25 posts views Thread by KK | last post: by
1 post views Thread by Peter D. Dunlap | last post: by
4 posts views Thread by Hypo | last post: by
reply views Thread by Billy | last post: by
5 posts views Thread by Tom wilson | 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.