locked
Browser back button Click - Displays old total value RRS feed

  • Question

  • User-1284851152 posted

    Dear Memebers,

    In my asp.net project, i have used a label in the Header Content of the Master Page. The purpose of the label is to show the "Consolidated Total" amount of the products added in the cart. 

    ISSUE:

    After successfully adding the products into the Cart, if the user clicks the "browser back button" then the website displays the old value of "Consolidated Total". My requirement is that, i need to show only the latest Consolidated total value, even if the back button is clicked. 

    Can you any give me a clue, how to achieve my requirement?

    Tuesday, November 4, 2014 7:23 AM

Answers

  • User-760709272 posted

    You need to disable caching on the pages that have this control.  If it is in the master page then you'll need to disable caching on your whole site.  This is a very bad idea just to fix a back button issue that users are more than familiar with.  Users know that when they go "back" they get a cached page as that is how every other site on the internet works for them too.  My advice is to not bother fixing this, but google for disabling caching in asp.net and you'll find lots of examples, but it will negatively impact the performance of your server and the performance of the site on the client, all for nothing really.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 4, 2014 7:35 AM
  • User1508394307 posted

    Read http://support.microsoft.com/kb/234067 and either add suggested meta-tags in the header of aspx

    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="-1">

    or set them from the code behind

    Response.Expires = -1;  
    Response.Cache.SetNoStore();

    Depends on browser you might need to play with some more tags e.g. read 

    http://forums.asp.net/t/1013531.aspx?How+to+prevent+browser+and+proxy+caching+of+web+pages 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 4, 2014 7:47 AM

All replies

  • User-760709272 posted

    You need to disable caching on the pages that have this control.  If it is in the master page then you'll need to disable caching on your whole site.  This is a very bad idea just to fix a back button issue that users are more than familiar with.  Users know that when they go "back" they get a cached page as that is how every other site on the internet works for them too.  My advice is to not bother fixing this, but google for disabling caching in asp.net and you'll find lots of examples, but it will negatively impact the performance of your server and the performance of the site on the client, all for nothing really.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 4, 2014 7:35 AM
  • User1508394307 posted

    Read http://support.microsoft.com/kb/234067 and either add suggested meta-tags in the header of aspx

    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="-1">

    or set them from the code behind

    Response.Expires = -1;  
    Response.Cache.SetNoStore();

    Depends on browser you might need to play with some more tags e.g. read 

    http://forums.asp.net/t/1013531.aspx?How+to+prevent+browser+and+proxy+caching+of+web+pages 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 4, 2014 7:47 AM
  • User-1284851152 posted

    @AidyF

    Many thanks for your immediate response. I too considered that disabling cache would cause the serious performance problem in asp.net sites. Anyway i will look for any other better solution .

    @smirnov Thanks for your reply. Do you have any other idea rather than disabling "Cache".

    Tuesday, November 4, 2014 9:22 AM
  • User1508394307 posted

    Do you have any other idea rather than disabling "Cache".

    Doesn't it work?

    I could imagine

    a) instead of having a label you could request total value via javascript+webservice (as a separate call, which you could even request e.g. every 10 sec, if you want). So instead of doing Label1.Text = total; you create a webservice which will return actual value of total. The webservice will be called via js and returned value will be assigned to a div control.
    b) another idea you could have a datetime value e.g. <%=DateTime.Now()%> which you could check from javascript on onload event and if it is older then e.g. 1 min do a refresh, etc. This will work only if server and client have the same time (so not very good idea, but anyway)

    but the question is why to make it complicated? Currently it seems the problem is in that fact that page was cached and when you click on Back button you got it from cache.

    Tuesday, November 4, 2014 9:36 AM