473,706 Members | 6,370 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Expire sAbsolute = DateTime.Now.Ad dDays(-1)
Response.Expire s = 0
Response.CacheC ontrol = "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 #1
29 3997
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*******@nosp am.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.Expire sAbsolute = DateTime.Now.Ad dDays(-1)
Response.Expire s = 0
Response.CacheC ontrol = "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 #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*******@nosp am.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.Expire sAbsolute = DateTime.Now.Ad dDays(-1)
Response.Expire s = 0
Response.CacheC ontrol = "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 #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="Tes tForm.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="Micros oft Visual Studio .NET 7.1"
name="GENERATOR ">
<meta content="Visual Basic .NET 7.1"
name="CODE_LANG UAGE">
<meta content="JavaSc ript"
name="vs_defaul tClientScript">
<meta
content="http://schemas.microso ft.com/intellisense/ie5"
name="vs_target Schema">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<%
Response.Buffer = True
Response.Expire sAbsolute = DateTime.Now.Ad dDays(-1)
Response.Expire s = 0
Response.CacheC ontrol = "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="PlaceHolder 1"
runat="server"> </asp:placeholder ></form>
</body>
</HTML>

The Page_Load:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Response.Cache. SetCacheability (HttpCacheabili ty.NoCache)
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).Group Name = "1"
PlaceHolder1.Co ntrols.Add(Radi os(x))
Next
Response.Cache. SetCacheability (HttpCacheabili ty.NoCache)
End Sub
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e
As System.EventArg s) 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*******@nosp am.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.Expire sAbsolute = DateTime.Now.Ad dDays(-1)
Response.Expire s = 0
Response.CacheC ontrol = "no-cache"
%>

I've tried adding this to the Page_Load event:

Response.Cache .SetCacheabilit y(HttpCacheabil ity.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 #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.......A LL 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******@NOyah oo.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*******@nosp am.com> wrote in message
news:ma******** *************** *********@4ax.c om...
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*******@nosp am.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.Expire sAbsolute = DateTime.Now.Ad dDays(-1)
Response.Expire s = 0
Response.CacheC ontrol = "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 #8
As per advice I've tried this in the Page_Load:

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

And this:

Response.Expire s = 0
Response.Cache. SetNoStore()
Response.Append Header("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*******@nosp am.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.Expire sAbsolute = DateTime.Now.Ad dDays(-1)
Response.Expire s = 0
Response.CacheC ontrol = "no-cache"
%>

I've tried adding this to the Page_Load event:

Response.Cache .SetCacheabilit y(HttpCacheabil ity.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 #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:Text Box id="TextBox1" runat="server"> </asp:TextBox>
</p>
<p>
&nbsp;<asp:Butt on 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*******@nosp am.com> wrote in message
news:h7******** *************** *********@4ax.c om...
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.......A LL 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******@NOyah oo.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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2417
by: news.microsoft.com | last post by:
Hello group, My goal is to attach an image over another image. Top image should be transparent so the back image is visible through the top one. Bellow is a test code in VB.NET. You need to create a form, a button (Button1) and an Picture Box (picBox). "watermark.jpg" is any jpg image, "beispiel.tif" is a multipage TIFF image with the white background, which will turn to transparent. The most important thing here is that the TIFF image...
25
7581
by: KK | last post by:
Hi, I am using history.go(-1) for implementing the back button functionality. Its working fine but with this exception. 1. The page which is having back button has some hyperlinks on it. 2. When anybody click on those links, it will open a new windown.
1
4283
by: Peter D. Dunlap | last post by:
Hello, I realize that this may not be the best place to ask this question, through the application is asp.net. I also realize that questions about disabling the back button are generally met with derision, so let me explain: (1) The site is actually a web-based application, not a "web site" per say, and is not accessable by the public. It is an application used internally by the company I work for, though it accessed by employees
4
7601
by: Hypo | last post by:
I added a 'Back' button to my page, and wrote 'OnClick' code something like this: Response.Write("<script>history.go(-" + iDepthIndex.ToString() + ");</script>"); But, it dosnt work! Effect is that browser navigates to desired page as expected and go back from where it started! But, the 'Back' button on browser works normaly. I dont get it!!??
0
1063
by: Billy | last post by:
Hi I'm really having a hard time dealing with dialog box under asp.net. I'm trying to create a function that will register some javascript that ask a question to the user, using the confirm() function. Function Confirm(ByVal Msg As String, ByVal TBName As String, ByVal Pa As Page)
8
2576
by: Galina | last post by:
Hello I have 6 dependent list boxes on my ASP page:  Faculty;  Lecturer;  Course;  Course occurrence;  Group;  Week commencing date. When faculty is selected, lists of lecturers and courses are populated. When course is selected, lists of occurrences, groups and
5
2394
by: Tom wilson | last post by:
I'm developing an application that is a benefits enrolment website. The benefits can be of any type in any order as stored in a SQL server. On each page is a Back and Next button. At a certain point in the initialization of the app, I determine a navigational structure; what benefit is first, second, etc., therefore, which page to display first, second and so on. In session memory I store an array of page URL's and a single value...
0
1318
by: BillE | last post by:
PROBLEM SUMMARY -- I use "Response.Cache.SetCacheability(HTTPCacheability.NoCache)" to force a page to reload instead of displaying cached content. However, I don't really want to reload the page since the data may still be inconsistent, if the page was called from a url and based on values in a querystring. I'm using VS 2005, VB.NET. DETAILS --
0
8780
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9285
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9155
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8989
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7901
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6614
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4445
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4708
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2499
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.