Sunday, April 10, 2011

Problem: ASP.NET page not updating the content of page

Impact: Sometimes when you are working with xml(or some other data source) and changes are made to the xml file. These changes are not reflected in the aspx page.

Solution: When I first started working with XML and ASP.NET, I came across this problem. I was working on an project where I was supposed to create a xml file of user comments. When a user posted comment, the comment was written to the xml file but was not shown on the aspx page. I tried refreshing the page, response.Redirect() and server.Transfer() but was not able to get the currently posted comments.

To get rid of this problem simply write Response.Cache.SetNoStore(); in the Page_Load method.

Example:

protected void Page_Load(object sender, EventArgs e)
{
        Response.Cache.SetNoStore();
        Response.Expires = -1000;
}

No comments:

Post a Comment