AjaxManager causes error when using System.Web.Caching.Cache property

7 posts, 0 answers
  1. Mallory
    Mallory avatar
    13 posts
    Member since:
    Mar 2010

    Posted 09 Mar 2010 Link to this post

    Hi everyone
    I'm fighting with this issue for quite a long time now, and so I thought this would be the right place to ask a question regarding this little issue.

    Every time I try to cache data with the System.Web.Caching.Cache property, I get the 'Controls cannot be ajaxified after Page PreRender.'-error at the line where I call AddAjaxSettings on the RadAjaxManager. When I remove the caching lines, everything just works fine. I sincerely do not know why the usage of the Cache property causes the AjaxManager to throw an exception. 

    The following describes the faulty scenario:
    I have a RadTreeView in the Master page. When a node of it is dropped, some data I want to cache is loaded into a RadGrid which is placed in the Default.aspx page. After this step the thing crashes (the first time - the data is not in the cache yet - it loads the data into the grid; the second time - data is in the cache now - it throws the abovementioned exception). The caching code is actually very simple:
    BindingList<string> strings = Cache["LotsOfItems"as BindingList<string>; 
    if (strings == null
        strings = MyClass.GetLotsOfStrings(); 
        Cache.Insert("LotsOfItems", strings, null, DateTime.Now.AddMinutes(1), Cache.NoSlidingExpiration); 
     
    myGrid.DataSource = strings; 
    myGrid.DataBind(); 


    I hope somebody can help me out with this one. I'll provide further information if needed.

    Thanks very much.

    Kind regards,
    Mallory
  2. Yeroon
    Yeroon avatar
    87 posts
    Member since:
    Oct 2012

    Posted 09 Mar 2010 Link to this post

    Hi,

    In exactly what event do you use the posted code? Node drop of treeview or page load or prerender override?

    /Yeroon
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mallory
    Mallory avatar
    13 posts
    Member since:
    Mar 2010

    Posted 10 Mar 2010 Link to this post

    Hi Yveroon

    Thanks for your reply. I use the listed code in the NodeDrop event handler of the RadTreeView

    Greetings
    Mallory
  5. Yeroon
    Yeroon avatar
    87 posts
    Member since:
    Oct 2012

    Posted 10 Mar 2010 Link to this post

    Hi,

    Sorry I wasn't very clear in my question. Where do you ajaxify the controls?

    So where do you put what you mention here: "error at the line where I call AddAjaxSettings on the RadAjaxManager"

    Because it causes a prerender error you might use the wrong moment to add the settings. Also check this thread. It might help:

    http://www.telerik.com/community/forums/aspnet-ajax/ajax/radajaxmanagerproxy-updating-controls-inside-a-formview-gives-errors.aspx


    /Yeroon
  6. Mallory
    Mallory avatar
    13 posts
    Member since:
    Mar 2010

    Posted 10 Mar 2010 Link to this post

    Hi Yveroon

    I actually placed that line of code into the Default.aspx page: ((MasterPage)Master).myAjaxManager.AjaxSettings.AddAjaxSetting(((MasterPage)Master)myTree, myGrid) ). This is done in the PreRender method (actually, if I place it in the Load method, it doesn't work either). 

    However, I actually solved the problem, but I'm not sure what exactly caused it to work. I now use a RadAjaxManagerProxy directly on the page (instead of casting the Master property) and everything works fine. It's somehow random, I can't reproduce the error at the moment (Heisenbug?). I think I just handled the usage of the Cache in a wrong way. I accessed the Cache from the wrong places. Now I placed the Cache operations into event handlers and methods that return the actual data (yes, I was doing it wrong, somehow).

    Thanks for that link. I had a look at it when the problem arised, but it didn't help. 

    I think the problem is solved now. If the problem should appear again, I'll have a deeper look at it. For now everything just works, and that's fine for me :)

    Thanks for your time and help.

    Regards,
    Mallory
  7. Yeroon
    Yeroon avatar
    87 posts
    Member since:
    Oct 2012

    Posted 10 Mar 2010 Link to this post

    Hi,

    Glad you solved it. The error was caused by the sometimes copmplex life cycle of masterpages, contectpages, usertcontrols etc. It's always a good idea to use a proxymanager if your master already has a main ajaxmanager.

    /Yeroon
  8. Mallory
    Mallory avatar
    13 posts
    Member since:
    Mar 2010

    Posted 10 Mar 2010 Link to this post

    Thanks. Yep, the whole lifecycle story is a pretty complex one. Also, I think it's a good practice to place as little code as possible into the Master page. Sometime you have to learn this the hard way (like I did ;)

    Regards,
    Mallory


Back to Top
UI for ASP.NET Ajax is Ready for VS 2017