Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
435
Problems using cache
posted

Hi,

I have a webhierarchicaldatagrid with paging linked to a webhierarchicaldatasource linked to an objectdatasource that returns a lot of records so i decided to enable the cache of the objectdatasource.

My problem is that i cant manage to refresh the cache and make the grid show the new data.

In my code i use a button to refresh the cache and when i click that button, the selecting method of the objectdatasource is called and the webhierarchicaldatagrid shows the first page of the data but when i click the "next page" link it shows no data and no prev or next page buttons.

This is the code i use to refresh the cache:

protected void btRefresh_Click(object sender, EventArgs e)

        {

            ObjectDataSource.EnableCaching = false;

            WHDGMovs.DataBind();        

            ObjectDataSource.EnableCaching = true;

        }

 

What am i doing wrong ?

Parents
No Data
Reply
  • 37874
    posted

    Hi fjVazquez,

    It has been some time since your post but in case that you still need assistance I will be happy to help.

    I would suggest to clear the cached data using something like the following code:

     

    Code Snippet
    1. protected void Page_Load(object sender, EventArgs e)
    2. {
    3.     if (!IsPostBack)
    4.     {
    5.         Cache[ObjectDataSource1.CacheKeyDependency] = "CacheExample";
    6.     }
    7. }
    8.  
    9.  
    10. protected void Button1_Click(object sender, EventArgs e)
    11. {
    12.     Cache.Remove(ObjectDataSource1.CacheKeyDependency);
    13.     Cache[ObjectDataSource1.CacheKeyDependency] = "CacheExample";
    14.     WebHierarchicalDataGrid1.DataBind();
    15. }

    If you have any other questions, please do not hesitate to ask.

Children