User Control inside RadAjaxManager

2 posts, 0 answers
  1. Abhishek
    Abhishek avatar
    21 posts
    Member since:
    Mar 2011

    Posted 16 Jan 2012 Link to this post

    My Asp Panel has a usercontrol inside it...User control is dynamicaly loaded.
    Asp panel is placed inside RadAjaxManager..
    User control contains drop down list and text boxes..

    on page load user control is loaded...
    But when I change selected index of drop down list inside user control...and do a postback....I receive an error...
    which says...

    "Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Failed to load viewstate.  The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.  For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request."

  2. Maria Ilieva
    Maria Ilieva avatar
    4017 posts

    Posted 16 Jan 2012 Link to this post

    Hi Abhishek,

    The reason for the error you are getting could be due to incorrect loading of the UserControls. If you are switching UserControls before the ViewState is loaded, ASP.NET will try to load the ViewState from the previously loaded user control into the new one. Thus, as the controls collection of the two does not match, an exception will thrown.
    For example if you are changing the userControl on a button click event you should load the new UserControls inside the button's click handler and use Page's Init event to load the same UserControl which has been loaded in the previous page request.

    I would also suggest you to review the following online resources which elaborates on Loading UserControls with Ajax:

    All the best,
    Maria Ilieva
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top