Response.redirect page load and browser back button

r s 21 Reputation points
2021-01-11T18:36:35.973+00:00

I have a repeater control that populates the data(Links with a query string).
example- PageOne .aspx

i look for the query string , create the URL by passing the query string (my function) and do a response.redirect. It goes to example PageTwo.aspx.

When i go to the PageTwo.aspx page and then click the back browser button it goes to the PageOne .aspx.

The problem i am having is when i do a back browser button and go back to the pageone , i am not able to hit the Page_Load(object sender, EventArgs e). in PageOne .aspx

Because of that i am not able to create the URL by passing the query string (my function) and when the user clicks again on the same URL, the url is broken.

SO it only works the first time.

 protected void Page_Load(object sender, EventArgs e)
        {

                 try
            {

                       if (Request.QueryString["MYId"] != null){
                         // creating the URL
                        var url = Helper.GetServiceLink(base.ContextItem,
                            Guid.Parse(Request.QueryString["MYId"]));

                    Response.Redirect(url.GetUrl(), false);
                     }

                /////   below creating the repeater control.

             }

}
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,246 questions
{count} votes

1 answer

Sort by: Most helpful
  1. SurferOnWww 1,906 Reputation points
    2021-01-12T03:09:36.23+00:00

    When i go to the PageTwo.aspx page and then click the back browser button it goes to the PageOne .aspx.

    I guess that "click the back browser button" does not request the PageOne.aspx but get the contents previously obtained from the cache of browser. It means that because no request was sent to the server by "click the back browser button" nothing (including the Page_Load) happened at the server side.

    I suggest that you try to control cache by adding code such like:

    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetExpires(DateTime.Now.ToUniversalTime());
    Response.Cache.SetMaxAge(new TimeSpan(0, 0, 0, 0));

    The above will generate the following response headers:

    Cache-Control: no-cache
    Pragma: no-cache
    Expires: -1

    Note that the above is only experimental try to confirm if the cache is issue.

    0 comments No comments