Pronunciation / adjective
Bringing something good and unforseen.
    Skip Navigation Links > Code Repository
   

Stop Browsers from Caching a Page so that Data Updates without Refreshing the Page



 
Return

Stop Browsers from Caching a Page so that Data Updates without Refreshing the Page

On occasion you'll have a browser render a cached version of a web page when you want the data shown to always be the most up to date. This can be especially annoying on posted forms where a user may see old data even though the underlying data really was updated.

To keep browsers from caching a page add the following to the page load routine:

  1. If Not Page.IsPostBack Then
  2. '---First page load only
  3. System.Web.HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache")
  4. System.Web.HttpContext.Current.Response.Expires = 0
  5. System.Web.HttpContext.Current.Response.Cache.SetNoStore()
  6. System.Web.HttpContext.Current.Response.AddHeader("Pragma", "no-cache")
  7. End If


Return
Microsoft Certified Professional   © 2017 Fortunate.  All rights reserved.
contact: justin@aboutfortunate.com