I have created a very simple example that doesn't work. Form1
contains a textbox and a button:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Response.Redirect("login.aspx")
End Sub
Very simple. Forget what login.aspx does, it's just somewhere to
redirect to.
So, I load this page, enter text and click the button. It takes me to
login.aspx. Fine.
Hit the back button and the textbox is empty. Why is the textbox
empty? Aren't .aspx pages supposed to maintain their state?
Both the textbox and the form have their viewstate properties set to
true.
Thanks! 7 2000
Tom:
They maintain their state through server-side round trips. That is, when
you click a linkbutton or a button the page will postback to itself and
state will be preserved. In your case, when you click Button1 the page
posts back to itself, and if you were to check the textbox text property,
you would see the value is maintained. When you Redirect you are going to
another page, at this point your persistante state is lost...the viewstate
is no longer kept. When you click back, you are going back to the original
page, state isn't maintained (it's already been thrown away)...it's like ur
visiting it for the first time. In other words, viewstate persists data
whilst doing roundtrips to the same page. The minute you Response.Redirect,
the viewstate is lost. hitting back is like requesting Form1 for the very
first time.
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/
"Tom wilson" <ye*******@nospam.com> wrote in message
news:55********************************@4ax.com... I have created a very simple example that doesn't work. Form1 contains a textbox and a button:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Response.Redirect("login.aspx") End Sub
Very simple. Forget what login.aspx does, it's just somewhere to redirect to.
So, I load this page, enter text and click the button. It takes me to login.aspx. Fine.
Hit the back button and the textbox is empty. Why is the textbox empty? Aren't .aspx pages supposed to maintain their state?
Both the textbox and the form have their viewstate properties set to true.
Thanks!
Tom:
They maintain their state through server-side round trips. That is, when
you click a linkbutton or a button the page will postback to itself and
state will be preserved. In your case, when you click Button1 the page
posts back to itself, and if you were to check the textbox text property,
you would see the value is maintained. When you Redirect you are going to
another page, at this point your persistante state is lost...the viewstate
is no longer kept. When you click back, you are going back to the original
page, state isn't maintained (it's already been thrown away)...it's like ur
visiting it for the first time. In other words, viewstate persists data
whilst doing roundtrips to the same page. The minute you Response.Redirect,
the viewstate is lost. hitting back is like requesting Form1 for the very
first time.
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/
"Tom wilson" <ye*******@nospam.com> wrote in message
news:55********************************@4ax.com... I have created a very simple example that doesn't work. Form1 contains a textbox and a button:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Response.Redirect("login.aspx") End Sub
Very simple. Forget what login.aspx does, it's just somewhere to redirect to.
So, I load this page, enter text and click the button. It takes me to login.aspx. Fine.
Hit the back button and the textbox is empty. Why is the textbox empty? Aren't .aspx pages supposed to maintain their state?
Both the textbox and the form have their viewstate properties set to true.
Thanks!
Ok, I understand that.
Lets start over, that was an inaccurate example.
This is a survey page that works like so:
- User gets page, fills out, submits
- Submit codeback sees entry errors and inserts error messages as
LiteralControls into the Placeholder sequence.
- The user gets the page back with the errors inline. All is ok.
At this point there are 2 choices:
1 - The user corrects the error and re-submits. That works.
or
2 - The user hits the back button to correct the error. In this case,
after clicking back, all the controls on the page are reset.
So there is no response.redirect at all here. If one moves forward
(correct, submit, correct, submit) it works perfect. If the back
button is clicked, the form reverts to its previous state (error
messages still in place) but the controls are all reset.
How does one deal with maintaining state when the user hits the Back
button?
On Mon, 14 Feb 2005 15:39:43 -0500, "Karl Seguin" <karl REMOVE @
REMOVE openmymind REMOVEMETOO . ANDME net> wrote: Tom: They maintain their state through server-side round trips. That is, when you click a linkbutton or a button the page will postback to itself and state will be preserved. In your case, when you click Button1 the page posts back to itself, and if you were to check the textbox text property, you would see the value is maintained. When you Redirect you are going to another page, at this point your persistante state is lost...the viewstate is no longer kept. When you click back, you are going back to the original page, state isn't maintained (it's already been thrown away)...it's like ur visiting it for the first time. In other words, viewstate persists data whilst doing roundtrips to the same page. The minute you Response.Redirect, the viewstate is lost. hitting back is like requesting Form1 for the very first time.
Karl
Ok, I understand that.
Lets start over, that was an inaccurate example.
This is a survey page that works like so:
- User gets page, fills out, submits
- Submit codeback sees entry errors and inserts error messages as
LiteralControls into the Placeholder sequence.
- The user gets the page back with the errors inline. All is ok.
At this point there are 2 choices:
1 - The user corrects the error and re-submits. That works.
or
2 - The user hits the back button to correct the error. In this case,
after clicking back, all the controls on the page are reset.
So there is no response.redirect at all here. If one moves forward
(correct, submit, correct, submit) it works perfect. If the back
button is clicked, the form reverts to its previous state (error
messages still in place) but the controls are all reset.
How does one deal with maintaining state when the user hits the Back
button?
On Mon, 14 Feb 2005 15:39:43 -0500, "Karl Seguin" <karl REMOVE @
REMOVE openmymind REMOVEMETOO . ANDME net> wrote: Tom: They maintain their state through server-side round trips. That is, when you click a linkbutton or a button the page will postback to itself and state will be preserved. In your case, when you click Button1 the page posts back to itself, and if you were to check the textbox text property, you would see the value is maintained. When you Redirect you are going to another page, at this point your persistante state is lost...the viewstate is no longer kept. When you click back, you are going back to the original page, state isn't maintained (it's already been thrown away)...it's like ur visiting it for the first time. In other words, viewstate persists data whilst doing roundtrips to the same page. The minute you Response.Redirect, the viewstate is lost. hitting back is like requesting Form1 for the very first time.
Karl
Tom:
it seems to me that choice #1 and #2 are the same thing (or atleast that the
user would be doing them for the same purpose). Not sure why users would hit
the back button to correct if it's clear that they can simply correct it on
the page infront ofthem and hit resumit (#1).
You can do a google search for 'ASP.net back button' and get a lot of
relevant hits. Remeber:
User views page.aspx
User submits and postback to page.aspx
from this point, when the user hits "back" it's like he/she is back at step
one, viewing page.aspx for the first time.
Not much you can do about it...but in my experience users know this is how
web apps work...fill out a form, get an error message and make
correction....they know not to hit back when the error message is staring
them in the face... Perhaps what you should do in addition to the error
message is display a red asterix next to the field in error so that their
attention is drawn there for correction instead of to the back button...
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/
"Tom wilson" <ye*******@nospam.com> wrote in message
news:25********************************@4ax.com... Ok, I understand that.
Lets start over, that was an inaccurate example.
This is a survey page that works like so:
- User gets page, fills out, submits - Submit codeback sees entry errors and inserts error messages as LiteralControls into the Placeholder sequence. - The user gets the page back with the errors inline. All is ok.
At this point there are 2 choices:
1 - The user corrects the error and re-submits. That works. or 2 - The user hits the back button to correct the error. In this case, after clicking back, all the controls on the page are reset.
So there is no response.redirect at all here. If one moves forward (correct, submit, correct, submit) it works perfect. If the back button is clicked, the form reverts to its previous state (error messages still in place) but the controls are all reset.
How does one deal with maintaining state when the user hits the Back button? On Mon, 14 Feb 2005 15:39:43 -0500, "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote:
Tom: They maintain their state through server-side round trips. That is, when you click a linkbutton or a button the page will postback to itself and state will be preserved. In your case, when you click Button1 the page posts back to itself, and if you were to check the textbox text property, you would see the value is maintained. When you Redirect you are going
toanother page, at this point your persistante state is lost...the
viewstateis no longer kept. When you click back, you are going back to the
originalpage, state isn't maintained (it's already been thrown away)...it's like
urvisiting it for the first time. In other words, viewstate persists data whilst doing roundtrips to the same page. The minute you
Response.Redirect,the viewstate is lost. hitting back is like requesting Form1 for the very first time.
Karl
It seems like a rather obvious hole in the technology. You know
somebody is going to click the back button and lose pages and pages of
data. I remember another developer I knew would not write delete
confirmations into his apps. When asked 'what if someone hits delete
by accident' his reply was 'who's going to do that'? A lot of people.
This page leads me to believe this can be done: 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. "
So according to this, this is a standard feature of asp.net yet I
can't get it to work. It seems a lot of people in this group ask
about disabling the back button but it's never a recommended practice.
I already do display error messages above the question in red, but
somebody's going to hit Back and freak out. They would tell me, as I
would say, 'I have yet to see an online form that says "DO NOT hit the
back button!!!!"'
I'll search around the web but I figured these being the Microsoft
newsgroups, that an answer to this would be simple and routine. Does
no one write apps capable of dealing with the back button and loss of
data?
Thanks for the replies...
On Tue, 15 Feb 2005 08:42:31 -0500, "Karl Seguin" <karl REMOVE @
REMOVE openmymind REMOVEMETOO . ANDME net> wrote: Tom: it seems to me that choice #1 and #2 are the same thing (or atleast that the user would be doing them for the same purpose). Not sure why users would hit the back button to correct if it's clear that they can simply correct it on the page infront ofthem and hit resumit (#1).
You can do a google search for 'ASP.net back button' and get a lot of relevant hits. Remeber:
User views page.aspx User submits and postback to page.aspx from this point, when the user hits "back" it's like he/she is back at step one, viewing page.aspx for the first time.
Not much you can do about it...but in my experience users know this is how web apps work...fill out a form, get an error message and make correction....they know not to hit back when the error message is staring them in the face... Perhaps what you should do in addition to the error message is display a red asterix next to the field in error so that their attention is drawn there for correction instead of to the back button...
Karl
Also in classic forms, if you hit the back button, the form fields will
still be with the data. (try!)
The viewstate gives you more options.
If in any case you want the form to be filled with the details, consider
using the session object to maitain data for each user. If you don't want
this, then add the ifpostback=false and reset all fields.
Leo
"Tom wilson" <ye*******@nospam.com> wrote in message
news:rf********************************@4ax.com... It seems like a rather obvious hole in the technology. You know somebody is going to click the back button and lose pages and pages of data. I remember another developer I knew would not write delete confirmations into his apps. When asked 'what if someone hits delete by accident' his reply was 'who's going to do that'? A lot of people.
This page leads me to believe this can be done:
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. "
So according to this, this is a standard feature of asp.net yet I can't get it to work. It seems a lot of people in this group ask about disabling the back button but it's never a recommended practice. I already do display error messages above the question in red, but somebody's going to hit Back and freak out. They would tell me, as I would say, 'I have yet to see an online form that says "DO NOT hit the back button!!!!"'
I'll search around the web but I figured these being the Microsoft newsgroups, that an answer to this would be simple and routine. Does no one write apps capable of dealing with the back button and loss of data?
Thanks for the replies... On Tue, 15 Feb 2005 08:42:31 -0500, "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote:
Tom: it seems to me that choice #1 and #2 are the same thing (or atleast that the user would be doing them for the same purpose). Not sure why users would hit the back button to correct if it's clear that they can simply correct it on the page infront ofthem and hit resumit (#1).
You can do a google search for 'ASP.net back button' and get a lot of relevant hits. Remeber:
User views page.aspx User submits and postback to page.aspx from this point, when the user hits "back" it's like he/she is back at step one, viewing page.aspx for the first time.
Not much you can do about it...but in my experience users know this is how web apps work...fill out a form, get an error message and make correction....they know not to hit back when the error message is staring them in the face... Perhaps what you should do in addition to the error message is display a red asterix next to the field in error so that their attention is drawn there for correction instead of to the back button...
Karl This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Fred |
last post by:
I have an aspx page: Main.aspx which has several components that cause
a postback. In the page Main.aspx I also have an iframe which contains
a multi-page pdf file.
The problem I am facing is...
|
by: Jeff Smythe |
last post by:
Why does Session_Start in Global.asax fire for every page opened during a
session of an ASP.NET application?
Am I wrong to expect that it would fire only when the first page (i.e., any
page in...
|
by: Stephanie_Stowe |
last post by:
Hi. I am trying to get used to AS.NET. I have been doing ASP classic for
years, and am now in a position to do ASP.NET. I am in the stumbling
around until I get my bearings phase. I hope you will...
|
by: Ralph Krausse |
last post by:
My source to my test is below. I am trying to figure out state. I
create a int and a Test object and set them to some value on
Page_Load. When I click my button on my web page, Button1_Click gets...
|
by: Tom wilson |
last post by:
I have created a very simple example that doesn't work. Form1
contains a textbox and a button:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles...
|
by: Carlos |
last post by:
Hi all,
I am currently working on a project that needs to
maintain the connection to the DB throughout the
pages that the user navigates. I have already validated
my DB connection and some...
|
by: Shadow Lynx |
last post by:
I realize that his question has been asked, in many other forms, many
times in this group. Even so, my tired eyes have not yet found a
sufficient answer, so I've decided to "reask" it even though...
|
by: Raj |
last post by:
Hi,
I am struggling with this for quite some time and thought will seek
your help on it. What I am doing is, I have Page1.aspx where user
inputs text into text boxes and also has a link to...
|
by: =?Utf-8?B?U2FjaGluIFNha2k=?= |
last post by:
I have asp application, from which I am redirecting user to .aspx page. I
want to use same sessions in .aspx application. When User clicks on Browsers
back button i.e. comes back from .aspx page to...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |