0

I have a gridview control in my default.aspx page, and in page_load of this control, I populate this gridview.

    protected void Page_Load(object sender, EventArgs e)
    {
        grd_UserOrderList.DataSource = UserOrderListData.GetOrderList();
        grd_UserOrderList.DataBind();
    }

What happens is that when I enter default.aspx page, I see 4 items in my gridview, I enter one of the items, and then click back button of the browser, I see 2 items. I checked the page_load function and it is not fired when back button is clicked. When I click refresh, again there is 4 items. I have this problem when working in my computer, but when I publish my project to server, I didn't have the same problem. What could be the reason? I am not looking for a temporary fix like disabling cache. I am using ie9 as browser.

HOY
  • 1,067
  • 10
  • 42
  • 85
  • Look here: http://stackoverflow.com/questions/961188/disable-browsers-back-button – Amiram Korach Aug 09 '12 at 08:29
  • Doesn't provide an answer for the "Reasons" that cache is not working as I expected, I am tring to find the root cause to fix the root. – HOY Aug 09 '12 at 08:47

1 Answers1

0

Try this. How to Refresh Page when called via the Back Button

Or you can try this.

We could disable the page cache. Then if we click the back button in the browser, the page will re-execute the page_load event to refresh the page.

The code is shown below.

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Response.Buffer = true;
                Response.CacheControl = "no-cache";
                Response.AddHeader("Pragma", "no-cache");
                Response.Expires = -1441;
            }
            Response.Write(DateTime.Now.ToString());
        }

This also might help you.

<script language="JavaScript">

  javascript:window.history.forward(1);

</script>
Krishna Thota
  • 6,646
  • 14
  • 54
  • 79
  • Thanks for the answer but I am not looking for an alternative fix, I am look for the reason why cache is not working as expected. – HOY Aug 09 '12 at 08:46
  • Because there will be cache in browser and the previous page will be present in the cache so for performance it loads. so pageload will not be executed. – Krishna Thota Aug 09 '12 at 08:50