RadAjaxManager and Dynamically loaded controls

2 posts, 0 answers
  1. bogdan
    bogdan avatar
    9 posts
    Member since:
    Mar 2009

    Posted 23 Jun 2012 Link to this post

    Hello.
    I have a MasterPage setup in a Web Application.
    Based on different button clicks i load dynamically different usercontrols in a contentplaceholder.

    ContentPlaceHolder cph = this.FindControl("ContentPlaceHolder1") as ContentPlaceHolder;
          UserControl uc = this.LoadControl("~/UserControls/" + strName + ".ascx") as UserControl;
     
          if ((cph != null) && (uc != null))
          {
              uc.ID = strName;
              cph.Controls.Clear();
              cph.Controls.Add(uc);
              IsControlAdded = true;
              ViewState[IDS_USERCONTROL] = strName;
          }

    The problem is that i need in Site.Master to use some js code that exists in a dynamically loaded usercontrol.
    That seems to be no problem for the first loaded usercontrol because the usercontrols html is included in the master page html.
    The problem arrises when i dynimically load the second usercontrol i find out that the html and js from the first usercontrol loaded persists in the master page and the second usercontrol's js and html is not loaded.

    If i add EnableAJAX="false" to the radajaxmanager it solves my problem .. but then again .. that beats the purpose of using ajaxmanager.
     
    switch (index) {
     case 0: //Person
         var arr = GetSelectedPerson();                            
         args.set_cancel(true);
         break;
     case 1: //Company
         break;
     case 2: //Group
         var arr = GetSelectedGroups();
        break;

    This is a code snipplet from Site.Master
    GetSelectedPerson and GetSelectedGroups are two js methods that exist in different usercontrols.

  2. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 27 Jun 2012 Link to this post

    Hello Bogdan,

    Please ensure that you are loading the UserControls correctly as described in the online resources below:
    http://www.telerik.com/help/aspnet-ajax/ajax-load-user-controls.html
    http://demos.telerik.com/aspnet-ajax/ajax/examples/common/loadingusercontrols/defaultcs.aspx


    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