Monday, August 16, 2010

How can I stop ASP .NET 2.0 caching my datagrid?

I have a form that I am using to post data to a database table and a gridview on the same page that is displaying the data.





When I post the data, the grid view is not updated until I manually reload the page.





I know that the whole page is not being cached becuase I have printed the current time and this changes when the form is submitted.How can I stop ASP .NET 2.0 caching my datagrid?
You see the page is not being cached, but the data is being loaded from ViewState. Make sure you refresh the GridView after updating the DataSource.





private void Page_Load( ... ) {


if(!Page.IsPostBack() {


BindGridView();


}


}





private void BindGridView() {


//set DataSource of your GridView


//call the DataBind() method of your GridView


}





//call the BindGridView() method whenever you update your DataSource








Hope this helps.How can I stop ASP .NET 2.0 caching my datagrid?
This may be of interest to you :


http://msdn.microsoft.com/msdnmag/issues鈥?/a>
Make sure the method that populates the GridView is being executed when the page posts back and not just on first load.
  • web hosting talk
  • loan
  • No comments:

    Post a Comment