1
votes

There are several similar questions posted here but none that address my question exactly. Here is the (simplified) scenario:

Page1.aspx: The user lands on Page1.aspx, and clicks a button. During the postback, the user is redirected to Page2.aspx (via a Response.Redirect).

Page2.aspx In the page load event for Page2.aspx, some validation occurs, and then a further redirect to Page3.aspx occurs (again via Response.Redirect).

Page3.aspx Simply displays some information to the user. No problem there.

Now the problem occurs when the user is on Page3.aspx, and hits the back button in their browser. In this scenario, I want Page2.aspx to re-load, so the validation is carried out once again. However, Page2.aspx is effectively bypassed and Page1.aspx is re-loaded (and only when I turn off the caching for the page). Turning off the caching for Page2.aspx does not make a difference.

So, my question is, is there a way to get Page2.aspx to run when the user clicks the back button in their browser?

2
Can you indicate your code for Page 2? - Greg
Sorry - can't post the code unfortunately. For the purposes of the question it is simply a response.redirect to Page3.aspx. - Ash
Then can you fill in the gap of how your persisting the relevant data from Page 1 to Page 2 and the potential deviation to your code flow that sends them to Page 3? - Greg

2 Answers

4
votes

try putting this in the code behind on page 2, I put it above page_load and it seemed to make the page fire the code behind after they pressed the back button.

   protected override void OnInit(EventArgs e)
    {
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetNoStore();
        Response.Cache.SetExpires(DateTime.MinValue);

        base.OnInit(e);
    }
0
votes

Andrew

A little trick with a flag in a session variable

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    If Not Page.IsPostBack Then
        If Session("flag") = 1 Then
            Session("flag") = 0
            Response.Write("<script>window.location.reload();</script>")
        End If
    Else
        Session("flag") = 1
    End If
End Sub

Protected Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
    Response.Redirect("Page3.aspx")
End Sub

Hope help you