Caching content by the browsers can be sometimes very annoying. I had problems with it,  mostly when I was developing some popup modal dialogs which showed aspx or ascx controls.

Thankfully, there is very simple solution how to disable content caching. You achieve it in two ways:

1. Directly in the ASPX or ASCX using below code:


<% System.Web.HttpContext.Current.Response.AddHeader( "Cache-Control","no-cache");
System.Web.HttpContext.Current.Response.Expires = 0;
System.Web.HttpContext.Current.Response.Cache.SetNoStore();
System.Web.HttpContext.Current.Response.AddHeader("Pragma", "no-cache");%>

2. From the codebehind, for example in the OnLoad event:


protected override void OnLoad(EventArgs e)

{

System.Web.HttpContext.Current.Response.AddHeader( "Cache-Control","no-cache");
System.Web.HttpContext.Current.Response.Expires = 0;
System.Web.HttpContext.Current.Response.Cache.SetNoStore();
System.Web.HttpContext.Current.Response.AddHeader("Pragma", "no-cache");

}