469,568 Members | 1,519 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,568 developers. It's quick & easy.

Page_Load method issues with Back Button

Hi,

I have a question regarding the Page_Load method and Back Button of
Internet explorer. I have created a webform. In that webform I have several
Text Boxes. Also I have two buttons. When I click on button1, it populates
the text boxes with person1 details. When I click on button2, it populates
the text box with person2 details and redirects to webform2. In webform2 if I
click on Back Button of Internet Explorer it should display details of
person2. But I am getting details of person1. I am thinking the reason for
this might be like this. When I Click on button1 in webform1, it actually
creates a new webform1. when I click on button2 on this new webform1 it is
actually not creating the new webform but just redirecting to webform2. So
when I click on back button it is displaying person1 details. Is there a
workaround for this? Please let me know.

Thnx,
Sridhar.
Jan 11 '06 #1
7 2228
Sridhar,

You're very close to figuring this out yourself. You are somewhat correct in
saying that the second button click doesn't create the web form. The web
form does get created on the server. But the server is never sending it to
the client. Instead the client receives the response.redirect and still has
the original first form in it's cache.

To work around this problem your redirect has to occurr client side. The way
I would do it would be to populate the second instance of the form and send
it back to the client but also send back a clientside startup script (i.e.
RegisterStartupScript) that will use a javascript redirect to send the
client to the new page. This way the client will actually cache the second
version of the form. However, you may need to do something special in that
script so that the redirect doesn't occurr if the back button has been hit.

A sample javascript redirect script is here:
http://www.codeave.com/javascript/code.asp?u_log=7002
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Sridhar" <Sr*****@discussions.microsoft.com> wrote in message
news:A8**********************************@microsof t.com...
Hi,

I have a question regarding the Page_Load method and Back Button of
Internet explorer. I have created a webform. In that webform I have
several
Text Boxes. Also I have two buttons. When I click on button1, it populates
the text boxes with person1 details. When I click on button2, it populates
the text box with person2 details and redirects to webform2. In webform2
if I
click on Back Button of Internet Explorer it should display details of
person2. But I am getting details of person1. I am thinking the reason for
this might be like this. When I Click on button1 in webform1, it actually
creates a new webform1. when I click on button2 on this new webform1 it is
actually not creating the new webform but just redirecting to webform2. So
when I click on back button it is displaying person1 details. Is there a
workaround for this? Please let me know.

Thnx,
Sridhar.

Jan 11 '06 #2
Hi Justin,

Thanks for the clarification. In fact I did use the
RegisterStartupScript to do that. But as you said I need to do something
special in that script so that the redirect doesn't occurr if the back
button has been hit. I am not knowing how to do that. Can you give me some
ideas on how to do that?

Thnx,
Sridhar.

"S. Justin Gengo" wrote:
Sridhar,

You're very close to figuring this out yourself. You are somewhat correct in
saying that the second button click doesn't create the web form. The web
form does get created on the server. But the server is never sending it to
the client. Instead the client receives the response.redirect and still has
the original first form in it's cache.

To work around this problem your redirect has to occurr client side. The way
I would do it would be to populate the second instance of the form and send
it back to the client but also send back a clientside startup script (i.e.
RegisterStartupScript) that will use a javascript redirect to send the
client to the new page. This way the client will actually cache the second
version of the form. However, you may need to do something special in that
script so that the redirect doesn't occurr if the back button has been hit.

A sample javascript redirect script is here:
http://www.codeave.com/javascript/code.asp?u_log=7002
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Sridhar" <Sr*****@discussions.microsoft.com> wrote in message
news:A8**********************************@microsof t.com...
Hi,

I have a question regarding the Page_Load method and Back Button of
Internet explorer. I have created a webform. In that webform I have
several
Text Boxes. Also I have two buttons. When I click on button1, it populates
the text boxes with person1 details. When I click on button2, it populates
the text box with person2 details and redirects to webform2. In webform2
if I
click on Back Button of Internet Explorer it should display details of
person2. But I am getting details of person1. I am thinking the reason for
this might be like this. When I Click on button1 in webform1, it actually
creates a new webform1. when I click on button2 on this new webform1 it is
actually not creating the new webform but just redirecting to webform2. So
when I click on back button it is displaying person1 details. Is there a
workaround for this? Please let me know.

Thnx,
Sridhar.


Jan 11 '06 #3
Sridhar,

Off the top of my head here's the way I think I'd try first:

Create a hidden filed on the form that can hold a value which will tell your
startup script if it should run or not. Just before the script does the
redirect set the hidden field to a different value. I believe that when the
back button is clicked the hidden field will retain the new value and may be
used to keep the script from running.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Sridhar" <Sr*****@discussions.microsoft.com> wrote in message
news:5B**********************************@microsof t.com...
Hi Justin,

Thanks for the clarification. In fact I did use the
RegisterStartupScript to do that. But as you said I need to do something
special in that script so that the redirect doesn't occurr if the back
button has been hit. I am not knowing how to do that. Can you give me some
ideas on how to do that?

Thnx,
Sridhar.

"S. Justin Gengo" wrote:
Sridhar,

You're very close to figuring this out yourself. You are somewhat correct
in
saying that the second button click doesn't create the web form. The web
form does get created on the server. But the server is never sending it
to
the client. Instead the client receives the response.redirect and still
has
the original first form in it's cache.

To work around this problem your redirect has to occurr client side. The
way
I would do it would be to populate the second instance of the form and
send
it back to the client but also send back a clientside startup script
(i.e.
RegisterStartupScript) that will use a javascript redirect to send the
client to the new page. This way the client will actually cache the
second
version of the form. However, you may need to do something special in
that
script so that the redirect doesn't occurr if the back button has been
hit.

A sample javascript redirect script is here:
http://www.codeave.com/javascript/code.asp?u_log=7002
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Sridhar" <Sr*****@discussions.microsoft.com> wrote in message
news:A8**********************************@microsof t.com...
> Hi,
>
> I have a question regarding the Page_Load method and Back Button of
> Internet explorer. I have created a webform. In that webform I have
> several
> Text Boxes. Also I have two buttons. When I click on button1, it
> populates
> the text boxes with person1 details. When I click on button2, it
> populates
> the text box with person2 details and redirects to webform2. In
> webform2
> if I
> click on Back Button of Internet Explorer it should display details of
> person2. But I am getting details of person1. I am thinking the reason
> for
> this might be like this. When I Click on button1 in webform1, it
> actually
> creates a new webform1. when I click on button2 on this new webform1 it
> is
> actually not creating the new webform but just redirecting to webform2.
> So
> when I click on back button it is displaying person1 details. Is there
> a
> workaround for this? Please let me know.
>
> Thnx,
> Sridhar.


Jan 11 '06 #4
Hi Justin,

Thank you for taking time in replying back. I tried that but it is not
retaining the new value. It is going back to the past value. So again it is
redirecting it.

Thnx,
Sridhar.

"S. Justin Gengo" wrote:
Sridhar,

Off the top of my head here's the way I think I'd try first:

Create a hidden filed on the form that can hold a value which will tell your
startup script if it should run or not. Just before the script does the
redirect set the hidden field to a different value. I believe that when the
back button is clicked the hidden field will retain the new value and may be
used to keep the script from running.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Sridhar" <Sr*****@discussions.microsoft.com> wrote in message
news:5B**********************************@microsof t.com...
Hi Justin,

Thanks for the clarification. In fact I did use the
RegisterStartupScript to do that. But as you said I need to do something
special in that script so that the redirect doesn't occurr if the back
button has been hit. I am not knowing how to do that. Can you give me some
ideas on how to do that?

Thnx,
Sridhar.

"S. Justin Gengo" wrote:
Sridhar,

You're very close to figuring this out yourself. You are somewhat correct
in
saying that the second button click doesn't create the web form. The web
form does get created on the server. But the server is never sending it
to
the client. Instead the client receives the response.redirect and still
has
the original first form in it's cache.

To work around this problem your redirect has to occurr client side. The
way
I would do it would be to populate the second instance of the form and
send
it back to the client but also send back a clientside startup script
(i.e.
RegisterStartupScript) that will use a javascript redirect to send the
client to the new page. This way the client will actually cache the
second
version of the form. However, you may need to do something special in
that
script so that the redirect doesn't occurr if the back button has been
hit.

A sample javascript redirect script is here:
http://www.codeave.com/javascript/code.asp?u_log=7002
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Sridhar" <Sr*****@discussions.microsoft.com> wrote in message
news:A8**********************************@microsof t.com...
> Hi,
>
> I have a question regarding the Page_Load method and Back Button of
> Internet explorer. I have created a webform. In that webform I have
> several
> Text Boxes. Also I have two buttons. When I click on button1, it
> populates
> the text boxes with person1 details. When I click on button2, it
> populates
> the text box with person2 details and redirects to webform2. In
> webform2
> if I
> click on Back Button of Internet Explorer it should display details of
> person2. But I am getting details of person1. I am thinking the reason
> for
> this might be like this. When I Click on button1 in webform1, it
> actually
> creates a new webform1. when I click on button2 on this new webform1 it
> is
> actually not creating the new webform but just redirecting to webform2.
> So
> when I click on back button it is displaying person1 details. Is there
> a
> workaround for this? Please let me know.
>
> Thnx,
> Sridhar.


Jan 11 '06 #5
when a user hits back, the browser generally fetchs the previous page from
its caches, no request is sent to the server. if the last request response
was a redirect, as it was in your case, then the redirect is done again. you
can turn of caching of your pages, which will cause the browser to resubmit
the form post, rather than fetch from the cache. this will cause the browser
to popup the dialog asking the user if they want to resubmit the form.

a better approach is design your site to be navigation friendly. in asp.net
1.0 don't overload a button like you have, either navigate, or save, but not
both. in asp.net 2.0 you can support this by posting to the new page, rather
than using redirect, then caching will work correctly.

-- bruce (sqlwork.com)

"Sridhar" <Sr*****@discussions.microsoft.com> wrote in message
news:A8**********************************@microsof t.com...
Hi,

I have a question regarding the Page_Load method and Back Button of
Internet explorer. I have created a webform. In that webform I have
several
Text Boxes. Also I have two buttons. When I click on button1, it populates
the text boxes with person1 details. When I click on button2, it populates
the text box with person2 details and redirects to webform2. In webform2
if I
click on Back Button of Internet Explorer it should display details of
person2. But I am getting details of person1. I am thinking the reason for
this might be like this. When I Click on button1 in webform1, it actually
creates a new webform1. when I click on button2 on this new webform1 it is
actually not creating the new webform but just redirecting to webform2. So
when I click on back button it is displaying person1 details. Is there a
workaround for this? Please let me know.

Thnx,
Sridhar.

Jan 11 '06 #6
Hi Bruce,

Thank you for the reply. I am using ASP.NET 1.1. I tried turning off
the cache. The problem is when the user clicks the Back Button, it says
"Warning: PAge has expired" something like that. Please click refresh. I
don't want to display that message every time the user hits the back button.
That is why I am going with this approach. If you know the workaround for
this situation please let me know.

Thnx,
Sridhar.

"Bruce Barker" wrote:
when a user hits back, the browser generally fetchs the previous page from
its caches, no request is sent to the server. if the last request response
was a redirect, as it was in your case, then the redirect is done again. you
can turn of caching of your pages, which will cause the browser to resubmit
the form post, rather than fetch from the cache. this will cause the browser
to popup the dialog asking the user if they want to resubmit the form.

a better approach is design your site to be navigation friendly. in asp.net
1.0 don't overload a button like you have, either navigate, or save, but not
both. in asp.net 2.0 you can support this by posting to the new page, rather
than using redirect, then caching will work correctly.

-- bruce (sqlwork.com)

"Sridhar" <Sr*****@discussions.microsoft.com> wrote in message
news:A8**********************************@microsof t.com...
Hi,

I have a question regarding the Page_Load method and Back Button of
Internet explorer. I have created a webform. In that webform I have
several
Text Boxes. Also I have two buttons. When I click on button1, it populates
the text boxes with person1 details. When I click on button2, it populates
the text box with person2 details and redirects to webform2. In webform2
if I
click on Back Button of Internet Explorer it should display details of
person2. But I am getting details of person1. I am thinking the reason for
this might be like this. When I Click on button1 in webform1, it actually
creates a new webform1. when I click on button2 on this new webform1 it is
actually not creating the new webform but just redirecting to webform2. So
when I click on back button it is displaying person1 details. Is there a
workaround for this? Please let me know.

Thnx,
Sridhar.


Jan 11 '06 #7
Sridhar,

Hmmmm, I was hoping the new value would be retained, but I wasn't sure...

I'll think about this and see if I can think of something... In the
short-run is there a reason not to just use panels and keep both forms on
the same page? Then there would be no redirect.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Sridhar" <Sr*****@discussions.microsoft.com> wrote in message
news:70**********************************@microsof t.com...
Hi Justin,

Thank you for taking time in replying back. I tried that but it is not
retaining the new value. It is going back to the past value. So again it
is
redirecting it.

Thnx,
Sridhar.

"S. Justin Gengo" wrote:
Sridhar,

Off the top of my head here's the way I think I'd try first:

Create a hidden filed on the form that can hold a value which will tell
your
startup script if it should run or not. Just before the script does the
redirect set the hidden field to a different value. I believe that when
the
back button is clicked the hidden field will retain the new value and may
be
used to keep the script from running.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Sridhar" <Sr*****@discussions.microsoft.com> wrote in message
news:5B**********************************@microsof t.com...
> Hi Justin,
>
> Thanks for the clarification. In fact I did use the
> RegisterStartupScript to do that. But as you said I need to do
> something
> special in that script so that the redirect doesn't occurr if the back
> button has been hit. I am not knowing how to do that. Can you give me
> some
> ideas on how to do that?
>
> Thnx,
> Sridhar.
>
> "S. Justin Gengo" wrote:
>
>> Sridhar,
>>
>> You're very close to figuring this out yourself. You are somewhat
>> correct
>> in
>> saying that the second button click doesn't create the web form. The
>> web
>> form does get created on the server. But the server is never sending
>> it
>> to
>> the client. Instead the client receives the response.redirect and
>> still
>> has
>> the original first form in it's cache.
>>
>> To work around this problem your redirect has to occurr client side.
>> The
>> way
>> I would do it would be to populate the second instance of the form and
>> send
>> it back to the client but also send back a clientside startup script
>> (i.e.
>> RegisterStartupScript) that will use a javascript redirect to send the
>> client to the new page. This way the client will actually cache the
>> second
>> version of the form. However, you may need to do something special in
>> that
>> script so that the redirect doesn't occurr if the back button has been
>> hit.
>>
>> A sample javascript redirect script is here:
>> http://www.codeave.com/javascript/code.asp?u_log=7002
>>
>>
>> --
>> Sincerely,
>>
>> S. Justin Gengo, MCP
>> Web Developer / Programmer
>>
>> www.aboutfortunate.com
>>
>> "Out of chaos comes order."
>> Nietzsche
>> "Sridhar" <Sr*****@discussions.microsoft.com> wrote in message
>> news:A8**********************************@microsof t.com...
>> > Hi,
>> >
>> > I have a question regarding the Page_Load method and Back Button
>> > of
>> > Internet explorer. I have created a webform. In that webform I have
>> > several
>> > Text Boxes. Also I have two buttons. When I click on button1, it
>> > populates
>> > the text boxes with person1 details. When I click on button2, it
>> > populates
>> > the text box with person2 details and redirects to webform2. In
>> > webform2
>> > if I
>> > click on Back Button of Internet Explorer it should display details
>> > of
>> > person2. But I am getting details of person1. I am thinking the
>> > reason
>> > for
>> > this might be like this. When I Click on button1 in webform1, it
>> > actually
>> > creates a new webform1. when I click on button2 on this new webform1
>> > it
>> > is
>> > actually not creating the new webform but just redirecting to
>> > webform2.
>> > So
>> > when I click on back button it is displaying person1 details. Is
>> > there
>> > a
>> > workaround for this? Please let me know.
>> >
>> > Thnx,
>> > Sridhar.
>>
>>
>>


Jan 11 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Alfons Puig | last post: by
4 posts views Thread by Christian Ista | last post: by
2 posts views Thread by Frank Schumacher | last post: by
3 posts views Thread by Imran Aziz | last post: by
1 post views Thread by puja | last post: by
17 posts views Thread by Arpan | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.