PageLoad when BACK is clicked

V

Viktor Popov

Hi everybody,

I would like to ask you if someone knows how to make a page to be loaded
again when th BACK Button of the Browser is clicked. What I mean is:
WebForm1(Load)->click link to
WebForm2->WebForm2(Load)->ClickBACKbuttonOFtheBROWSER->WebForm1(Load)

Thank you in advance!

Best regards,

Viktor
 
K

K-Kyc

uhh... I don't think that is possible (the .NET way at
least). Basically I think you could do this by JavaScript.
Detect (somehow) with javascript if the backbutton was
clicked, and if so, refresh the page.

ASP.NET is more server-side oriented. And the action you
are performing is Client-Side. So you have to do it client
side.

According to http://www.tek-tips.com/viewthread.cfm?
qid=897314 the detection of the Back button press is
impossible???

So I can suggest a way for you (the way I would do it).
Basically when you load the page, in a hidden field
somewhere have a time stamp of the loading date/time
i.e.
<INPUT TYPE="HIDDEN" NAME="TimeStamp" VALUE="Sep 6 2004
17:34:24">

And then also create a cookie with a timestamp (and set it
each time your page is loaded, but after you try to detect
the backbutton).

So now in your code run the javascript each time the page
is displayed/loaded (OnPageLoad I think???):
1. Retrieve the cookie timestamp value (into a var
cookieTimeStamp)
2. Retrieve the hidden form field value (into a var
pageTimeStamp).

After retrieving the values set the cookie to the current
time (so if you press the forward button the same thing
will occurr).
And then compare them. If the cookieTimeStamp is blank
(not set) or is less than the pageTimeStamp, then do
nothing. Otherwise reload the page. (you could actually do
this in one if statement, but I think this is easier to
present/explain).

When you reload the page that way, that will send a
request to the server which will cause your ASP code to be
executed again like you wanted.

I haven't done this before, but based on some other work I
have done, this should work :)

I know this is not exactly the Microsoft friendly way, but
if you really need to do this, then here is one way.

Actually I would be interested to see what other ways
people would come up with to do this.

Hope that helps.
 
V

Viktor Popov

I think that it is.
I hava included this <%@ OutputCache Location="None" %> and it works. What
do you mean?

Viktor
 
K

K-Kyc

Yeah actually you're right.... It does work....
I tested it and on each back button hit, it reloads the
page. However, it only works (in my test) if you load the
page only once... But if you have a form postback on your
page, and then browse away and hit back button you will
get the PAGE EXPIRED warning. So I guess your solution
would be very useful for pages that do not contain
forms...

Test it, and see if you get the same problem.
 
V

Viktor Popov

Hi,
In my case it works all the time. I've tryed abou 10 times and the page did
not expire.
Thanks for the help!

Viktor


Yeah actually you're right.... It does work....
I tested it and on each back button hit, it reloads the
page. However, it only works (in my test) if you load the
page only once... But if you have a form postback on your
page, and then browse away and hit back button you will
get the PAGE EXPIRED warning. So I guess your solution
would be very useful for pages that do not contain
forms...

Test it, and see if you get the same problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top