PageLoad when BACK is clicked

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: K-Kyc (anonymous_at_discussions.microsoft.com)
Date: 09/07/04


Date: Mon, 6 Sep 2004 19:55:08 -0700

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.

>-----Original Message-----
>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
>
>
>---
>Outgoing mail is certified Virus Free.
>Checked by AVG anti-virus system (http://www.grisoft.com).
>Version: 6.0.751 / Virus Database: 502 - Release Date:
02.9.2004 a.
>
>
>.
>



Relevant Pages