Back button question


D

DougS

I have an ASP.Net app and I'm trying to prevent the user from hitting the
back button to get back to page2.aspx from page3.aspx. I put this code in
page_init, page_load and page_prerender and it never fires except when I'm
coming into the page or posting back. When I go 'back' to the page it never
fires.

Dim sLastPage As String = Request.ServerVariables("HTTP_REFERER")
If sLastPage.IndexOf("Page1.aspx") < 5 And
sLastPage.IndexOf("Page2.aspx") < 1 Then
' if they did not come from Page1 or Page2 then send
' them back to where they came from
Response.Redirect(Request.ServerVariables("HTTP_REFERER"))
End If

Thanks for any help,
DougS
 
Ad

Advertisements

M

Mythran

DougS said:
I have an ASP.Net app and I'm trying to prevent the user from hitting the
back button to get back to page2.aspx from page3.aspx. I put this code in
page_init, page_load and page_prerender and it never fires except when I'm
coming into the page or posting back. When I go 'back' to the page it never
fires.

Dim sLastPage As String = Request.ServerVariables("HTTP_REFERER")
If sLastPage.IndexOf("Page1.aspx") < 5 And
sLastPage.IndexOf("Page2.aspx") < 1 Then
' if they did not come from Page1 or Page2 then send
' them back to where they came from
Response.Redirect(Request.ServerVariables("HTTP_REFERER"))
End If

Thanks for any help,
DougS

The thing you must understand about most browser back buttons is that they
reload the client-side html from their own cache. It doesn't normally cause
a post-back to the server. Because of this, you don't get the server-side
events (not post-back). So, you'd either have to check when the client
re-submits the web page, or something similar.

HTH,
Mythran
 
Ad

Advertisements


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

Top