Dynamic RadAjaxManager/RadAjaxManagerProxy

9 posts, 0 answers
  1. Dan Miller
    Dan Miller avatar
    23 posts
    Member since:
    Jul 2010

    Posted 06 Aug 2010 Link to this post

    I have a setup where I have a masterpage with a codebehind. I have another page that is a web file with a user control + codebehind that uses the master page. On the masterpage I have a RadAjaxManager that I am creating dynamically in the PageInit and adding to a placeholder on the masterpage:

    RadAjaxManager RadAjaxManagerMaster = new RadAjaxManager();
    RadAjaxManagerMaster.ID =
    "RadAjaxManagerMaster";

    AjaxSetting RadAjaxManagerMasterAjaxSettings =
    new AjaxSetting();

    RadAjaxManagerMasterAjaxSettings.AjaxControlID =
    "RadContextMenuMaster"

                    AjaxUpdatedControl RadWindowAjaxControl = new AjaxUpdatedControl(); 
                    RadWindowAjaxControl.ControlID = "RadWindowMaster";
     
                    AjaxUpdatedControl RadContextMenuAjaxControl = new AjaxUpdatedControl(); 
                    RadContextMenuAjaxControl.ControlID = "RadContextMenuMaster";
     
                    RadAjaxManagerMasterAjaxSettings.UpdatedControls.Add(RadWindowAjaxControl); 
                    RadAjaxManagerMasterAjaxSettings.UpdatedControls.Add(RadContextMenuAjaxControl); 
                    RadAjaxManagerMaster.AjaxSettings.Add(RadAjaxManagerMasterAjaxSettings); 
     
                    RadAjaxLoadingPanel RadAjaxLoadingPanelMaster = new RadAjaxLoadingPanel(); 
                    RadAjaxLoadingPanelMaster.ID = "RadAjaxLoadingPanelMaster";
                    RadAjaxLoadingPanelMaster.BackgroundPosition = AjaxLoadingPanelBackgroundPosition.Center;
     
                    PlaceHolder PlaceHolderCMSAdmin = (PlaceHolder)Shuware.ShuwareCommon.Web.FindControlByID(this.Controls, "PlaceHolderCMSAdmin");
                    if (PlaceHolderCMSAdmin != null)
                    {
                        PlaceHolderCMSAdmin.Controls.Add(RadAjaxManagerMaster);
                        PlaceHolderCMSAdmin.Controls.Add(RadAjaxLoadingPanelMaster);
                    }

    Yet when I run the page none of the ajax works at all. I read in another thread that you should create the radajaxmanager in the PageInit and the updated controls in the PageLoad, I tried this as well to no avail. This is inside the PageLoad:

    private void CreateAjaxSettings()
        {
            RadAjaxManagerProxy RadAjaxManagerProxy = (RadAjaxManagerProxy)Shuware.ShuwareCommon.Web.FindControlByID(this.Controls, "RadAjaxManagerProxy");
     
            AjaxSetting RadAjaxManagerProxyAjaxSettings = new AjaxSetting();
            RadAjaxManagerProxyAjaxSettings.AjaxControlID = "RadContextMenuMaster";
     
            AjaxUpdatedControl divCMSContentAjaxControl = new AjaxUpdatedControl();
            divCMSContentAjaxControl.ControlID = "divCMSContent";
            divCMSContentAjaxControl.LoadingPanelID = "radAjaxLoadingPanel";
     
            AjaxUpdatedControl RadPlaceholderAjaxControl = new AjaxUpdatedControl();
            RadPlaceholderAjaxControl.ControlID = "PlaceHolderContentCMS";
     
            AjaxUpdatedControl LabelDebugAjaxControl = new AjaxUpdatedControl();
            LabelDebugAjaxControl.ControlID = "LabelDebug";
     
            AjaxUpdatedControl RadWindowAjaxControl = new AjaxUpdatedControl();
            RadWindowAjaxControl.ControlID = "RadWindowMaster";
     
            AjaxUpdatedControl RadContextMenuAjaxControl = new AjaxUpdatedControl();
            RadContextMenuAjaxControl.ControlID = "RadContextMenuCMS";
     
            RadAjaxManagerProxyAjaxSettings.UpdatedControls.Add(divCMSContentAjaxControl);
            RadAjaxManagerProxyAjaxSettings.UpdatedControls.Add(RadPlaceholderAjaxControl);
            RadAjaxManagerProxyAjaxSettings.UpdatedControls.Add(LabelDebugAjaxControl);
            RadAjaxManagerProxyAjaxSettings.UpdatedControls.Add(RadWindowAjaxControl);
            RadAjaxManagerProxyAjaxSettings.UpdatedControls.Add(RadContextMenuAjaxControl);
            RadAjaxManagerProxy.AjaxSettings.Add(RadAjaxManagerProxyAjaxSettings);
        }

    And this is in the PageInit: (using a proxy because I have a RadAjaxManager on the masterpage for this file)

                RadAjaxManagerProxy RadAjaxManagerProxy = new RadAjaxManagerProxy();
                RadAjaxManagerProxy.ID = "RadAjaxManagerProxy";
     
                PlaceHolder PlaceHolderCMSAdmin = (PlaceHolder)Shuware.ShuwareCommon.Web.FindControlByID(this.Controls, "PlaceHolderCMSAdmin");
                if (PlaceHolderCMSAdmin != null)
                {
                    PlaceHolderCMSAdmin.Controls.Add(RadAjaxManagerProxy);
                }

    In both these instances absolutely no ajax works on the page. I used to have these controls on the actual page not in the codebehind and everything worked perfectly.
  2. Dan Miller
    Dan Miller avatar
    23 posts
    Member since:
    Jul 2010

    Posted 10 Aug 2010 Link to this post

    Ideas anyone?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 11 Aug 2010 Link to this post

    Hello Dan,

    I suppose that the problem could be caused by the fact that you are creating the RadAjaxManager control in the Page_Init event of the MasterPage which I suppose is a bit early. I would suggest you to test adding it in Page_Load event and verify if this will make any difference.

    All the best,
    Maria Ilieva
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Dan Miller
    Dan Miller avatar
    23 posts
    Member since:
    Jul 2010

    Posted 11 Aug 2010 Link to this post

    Thanks Maria! I moved everything into my Page_Load and it works like a charm.

    Edit: Turns out the pages function again, but still no ajax, see reply below.
  6. Dan Miller
    Dan Miller avatar
    23 posts
    Member since:
    Jul 2010

    Posted 19 Aug 2010 Link to this post

    I was off working on other projects all week but when I returned to the project using this code I realized that while the page is doing refreshes and functions correctly, the AJAX itself is not actually working and everything is doing full page postbacks. I have my RadAjaxManager built dynamically in the Page_Load in the code-behind on my masterpage. I have my RadAjaxManagerProxy built dynamically in the code behind of a user control that I am placing on a page that uses the masterpage with the RadAjaxManager on it. Here is the updated code:

    This is the function I call from the Page_Load in the masterpage.
    private void CreateAjaxSettings()
    {
        /*********************Rad Controls*********************
            Creates all of the RadControls that need to be on the page and put them on the page in the PlaceholderCMSAdmin.
            ******************************************************/
        RadWindowManager RadWindowManagerMaster = new RadWindowManager(); //needed for the blockConfirm to show.
        RadWindowManagerMaster.ID = "RadWindowManagerMaster";
     
        RadAjaxManager RadAjaxManagerMaster = new RadAjaxManager(); //controls all the ajax on the page
        RadAjaxManagerMaster.ID = "RadAjaxManagerMaster";
        RadAjaxManagerMaster.DefaultLoadingPanelID = "RadAjaxLoadingPanelMaster";
     
        AjaxSetting RadAjaxManagerMasterAjaxSettings = new AjaxSetting();
        RadAjaxManagerMasterAjaxSettings.AjaxControlID = "RadContextMenuMaster"; //the control on the page that triggers the ajax
     
        AjaxUpdatedControl RadWindowAjaxControl = new AjaxUpdatedControl(); //this control is updated with ajax
        RadWindowAjaxControl.ControlID = "RadWindowMaster";
     
        AjaxUpdatedControl RadContextMenuAjaxControl = new AjaxUpdatedControl(); //this control is updated with ajax
        RadContextMenuAjaxControl.ControlID = "RadContextMenuMaster";
     
        RadAjaxManagerMasterAjaxSettings.UpdatedControls.Add(RadWindowAjaxControl); //when RadContextMenuMaster does a postpack the RadWindowAjaxControl is updated with ajax
        RadAjaxManagerMasterAjaxSettings.UpdatedControls.Add(RadContextMenuAjaxControl); //when RadContextMenuMaster does a postpack the RadContextMenuAjaxControl is updated with ajax
        RadAjaxManagerMaster.AjaxSettings.Add(RadAjaxManagerMasterAjaxSettings); //adds the ajaxified controls to the ajax manager
     
        RadAjaxLoadingPanel RadAjaxLoadingPanelMaster = new RadAjaxLoadingPanel(); //loading panel for when the edit window is loading
        RadAjaxLoadingPanelMaster.ID = "RadAjaxLoadingPanelMaster";
        RadAjaxLoadingPanelMaster.Skin = "WebBlue";
        RadAjaxLoadingPanelMaster.EnableSkinTransparency = true;
        RadAjaxLoadingPanelMaster.BackgroundPosition = AjaxLoadingPanelBackgroundPosition.Center;
     
        PlaceHolder PlaceHolderCMSAdmin = (PlaceHolder)Shuware.ShuwareCommon.Web.FindControlByID(this.Controls, "PlaceHolderCMSAdmin");
        if (PlaceHolderCMSAdmin != null)
        {
            //adds the controls to the placeholder and puts them on the page
            PlaceHolderCMSAdmin.Controls.Add(RadAjaxManagerMaster);
            PlaceHolderCMSAdmin.Controls.Add(RadAjaxLoadingPanelMaster);
            PlaceHolderCMSAdmin.Controls.Add(RadWindowManagerMaster);
        }
        /*********************************************************/
    }

    This is the function I call from the Page_Load of my user control.
    private void CreateAjaxSettings() //Loads all the Ajax controls into the AjaxManagerProxy on the page.
    {
        RadAjaxManagerProxy RadAjaxManagerProxy = new RadAjaxManagerProxy();
        RadAjaxManagerProxy.ID = "RadAjaxManagerProxy";
     
        PlaceHolder PlaceHolderCMSAdmin = (PlaceHolder)Shuware.ShuwareCommon.Web.FindControlByID(this.Controls, "PlaceHolderCMSAdmin");
        if (PlaceHolderCMSAdmin != null)
            PlaceHolderCMSAdmin.Controls.Add(RadAjaxManagerProxy);
     
        AjaxSetting RadAjaxManagerProxyAjaxSettings = new AjaxSetting();
        RadAjaxManagerProxyAjaxSettings.AjaxControlID = "RadContextMenuMaster";
     
        AjaxUpdatedControl divCMSContentAjaxControl = new AjaxUpdatedControl();
        divCMSContentAjaxControl.ControlID = "divCMSContent";
        divCMSContentAjaxControl.LoadingPanelID = "radAjaxLoadingPanel";
     
        AjaxUpdatedControl RadPlaceholderAjaxControl = new AjaxUpdatedControl();
        RadPlaceholderAjaxControl.ControlID = "PlaceHolderContentCMS";
     
        AjaxUpdatedControl LabelDebugAjaxControl = new AjaxUpdatedControl();
        LabelDebugAjaxControl.ControlID = "LabelDebug";
     
        AjaxUpdatedControl RadWindowAjaxControl = new AjaxUpdatedControl();
        RadWindowAjaxControl.ControlID = "RadWindowMaster";
     
        AjaxUpdatedControl RadContextMenuAjaxControl = new AjaxUpdatedControl();
        RadContextMenuAjaxControl.ControlID = "RadContextMenuCMS";
     
        RadAjaxManagerProxyAjaxSettings.UpdatedControls.Add(divCMSContentAjaxControl);
        RadAjaxManagerProxyAjaxSettings.UpdatedControls.Add(RadPlaceholderAjaxControl);
        RadAjaxManagerProxyAjaxSettings.UpdatedControls.Add(LabelDebugAjaxControl);
        RadAjaxManagerProxyAjaxSettings.UpdatedControls.Add(RadWindowAjaxControl);
        RadAjaxManagerProxyAjaxSettings.UpdatedControls.Add(RadContextMenuAjaxControl);
        RadAjaxManagerProxy.AjaxSettings.Add(RadAjaxManagerProxyAjaxSettings);
    }

    If you need to see any other snippets of my code please let me know. I am completely baffled as to why the Ajax no longer functions.
  7. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 25 Aug 2010 Link to this post

    Hello Dan,

    Please excuse me for misleading you. The RadAjaxManager should be created and added on Page_Init. However the dynamic ajax setting should be added before Page_Load. You can use the Page_PreRender event as well.

    All the best,
    Maria
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Dan Miller
    Dan Miller avatar
    23 posts
    Member since:
    Jul 2010

    Posted 25 Aug 2010 Link to this post

    I have the RadAjaxManager and RadAjaxManagerProxy being created in the Page_Init and their settings are being added in the Page_PreRender function but the postbacks are still not using ajax.

    RadAjaxManagerProxy page:
    protected void Page_Init(object sender, EventArgs e)
        {
            if (IsAdmin)
            {
                LoadPageControls(); //loads all the dynamically created objects and controls onto the page
                CreateAjaxManagerProxy();
                //SetDockInitialize(typeof(RadDock));
            }
     
            if (ViewPermission)
                LoadContent(false);
        }
     
        protected void Page_PreRender(object senver, EventArgs e)
        {
            if (IsAdmin)
                CreateAjaxSettings();
        }
     
        private void CreateAjaxManagerProxy()
        {
            RadAjaxManagerProxy RadAjaxManagerProxy = new RadAjaxManagerProxy();
            RadAjaxManagerProxy.ID = "RadAjaxManagerProxy";
     
            PlaceHolder PlaceHolderCMSAdmin = (PlaceHolder)Shuware.ShuwareCommon.Web.FindControlByID(this.Controls, "PlaceHolderCMSAdmin");
            if (PlaceHolderCMSAdmin != null)
                PlaceHolderCMSAdmin.Controls.Add(RadAjaxManagerProxy);
        }
     
        private void CreateAjaxSettings() //Loads all the Ajax controls into the AjaxManagerProxy on the page.
        {
            AjaxSetting RadAjaxManagerProxyAjaxSettings = new AjaxSetting();
            RadAjaxManagerProxyAjaxSettings.AjaxControlID = "RadContextMenuMaster";
     
            AjaxUpdatedControl divCMSContentAjaxControl = new AjaxUpdatedControl();
            divCMSContentAjaxControl.ControlID = "divCMSContent";
            divCMSContentAjaxControl.LoadingPanelID = "radAjaxLoadingPanel";
     
            AjaxUpdatedControl RadPlaceholderAjaxControl = new AjaxUpdatedControl();
            RadPlaceholderAjaxControl.ControlID = "PlaceHolderContentCMS";
     
            AjaxUpdatedControl LabelDebugAjaxControl = new AjaxUpdatedControl();
            LabelDebugAjaxControl.ControlID = "LabelDebug";
     
            AjaxUpdatedControl RadWindowAjaxControl = new AjaxUpdatedControl();
            RadWindowAjaxControl.ControlID = "RadWindowMaster";
     
            AjaxUpdatedControl RadContextMenuAjaxControl = new AjaxUpdatedControl();
            RadContextMenuAjaxControl.ControlID = "RadContextMenuCMS";
     
            RadAjaxManagerProxyAjaxSettings.UpdatedControls.Add(divCMSContentAjaxControl);
            RadAjaxManagerProxyAjaxSettings.UpdatedControls.Add(RadPlaceholderAjaxControl);
            RadAjaxManagerProxyAjaxSettings.UpdatedControls.Add(LabelDebugAjaxControl);
            RadAjaxManagerProxyAjaxSettings.UpdatedControls.Add(RadWindowAjaxControl);
            RadAjaxManagerProxyAjaxSettings.UpdatedControls.Add(RadContextMenuAjaxControl);
     
            RadAjaxManagerProxy RadAjaxManagerProxy = (RadAjaxManagerProxy)this.FindControl("RadAjaxManagerProxy");
            RadAjaxManagerProxy.AjaxSettings.Add(RadAjaxManagerProxyAjaxSettings);
        }

    RadAjaxManager page:
    protected void Page_Init(object sender, EventArgs e)
            {
                //LabelDebug.Text += "Page_Init " + Page.IsPostBack.ToString() + " <br>";
                if (IsAdmin)
                {
                    LoadPageControls(); //this has to be done BEFORE the page load to put the controls on the page
              CreateAjaxManager();
                }
            }
     
                    protected void Page_PreRender(object senver, EventArgs e)
                    {
                        if (IsAdmin)   
                            CreateAjaxSettings();
                    }
     
                    private void CreateAjaxManager()
                    {
                        RadAjaxManager RadAjaxManagerMaster = new RadAjaxManager(); //controls all the ajax on the page
                        RadAjaxManagerMaster.ID = "RadAjaxManagerMaster";
                        RadAjaxManagerMaster.DefaultLoadingPanelID = "RadAjaxLoadingPanelMaster";
     
                         PlaceHolder PlaceHolderCMSAdmin = (PlaceHolder)Shuware.ShuwareCommon.Web.FindControlByID(this.Controls, "PlaceHolderCMSAdmin");
                         if (PlaceHolderCMSAdmin != null)
                         {
                             //adds the controls to the placeholder and puts them on the page
                             PlaceHolderCMSAdmin.Controls.Add(RadAjaxManagerMaster);
                         }
                    }
     
            private void CreateAjaxSettings()
            {
                /*********************Rad Controls*********************
                Creates all of the RadControls that need to be on the page and put them on the page in the PlaceholderCMSAdmin.
                ******************************************************/
                RadWindowManager RadWindowManagerMaster = new RadWindowManager(); //needed for the blockConfirm to show.
                RadWindowManagerMaster.ID = "RadWindowManagerMaster";
     
                AjaxSetting RadAjaxManagerMasterAjaxSettings = new AjaxSetting();
                RadAjaxManagerMasterAjaxSettings.AjaxControlID = "RadContextMenuMaster"; //the control on the page that triggers the ajax
     
                AjaxUpdatedControl RadWindowAjaxControl = new AjaxUpdatedControl(); //this control is updated with ajax
                RadWindowAjaxControl.ControlID = "RadWindowMaster";
     
                AjaxUpdatedControl RadContextMenuAjaxControl = new AjaxUpdatedControl(); //this control is updated with ajax
                RadContextMenuAjaxControl.ControlID = "RadContextMenuMaster";
     
                RadAjaxManagerMasterAjaxSettings.UpdatedControls.Add(RadWindowAjaxControl); //when RadContextMenuMaster does a postpack the RadWindowAjaxControl is updated with ajax
                RadAjaxManagerMasterAjaxSettings.UpdatedControls.Add(RadContextMenuAjaxControl); //when RadContextMenuMaster does a postpack the RadContextMenuAjaxControl is updated with ajax
     
                            RadAjaxManager RadAjaxManagerMaster = (RadAjaxManager)Shuware.ShuwareCommon.Web.FindControlByID(this.Controls, "RadAjaxManagerMaster");
                RadAjaxManagerMaster.AjaxSettings.Add(RadAjaxManagerMasterAjaxSettings); //adds the ajaxified controls to the ajax manager
     
                RadAjaxLoadingPanel RadAjaxLoadingPanelMaster = new RadAjaxLoadingPanel(); //loading panel for when the edit window is loading
                RadAjaxLoadingPanelMaster.ID = "RadAjaxLoadingPanelMaster";
                RadAjaxLoadingPanelMaster.Skin = "WebBlue";
                RadAjaxLoadingPanelMaster.EnableSkinTransparency = true;
                RadAjaxLoadingPanelMaster.BackgroundPosition = AjaxLoadingPanelBackgroundPosition.Center;
     
                PlaceHolder PlaceHolderCMSAdmin = (PlaceHolder)Shuware.ShuwareCommon.Web.FindControlByID(this.Controls, "PlaceHolderCMSAdmin");
                if (PlaceHolderCMSAdmin != null)
                {
                    //adds the controls to the placeholder and puts them on the page
                    PlaceHolderCMSAdmin.Controls.Add(RadAjaxLoadingPanelMaster);
                    PlaceHolderCMSAdmin.Controls.Add(RadWindowManagerMaster);
                }
                /*********************************************************/
            }
  9. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 26 Aug 2010 Link to this post

    Hi Dan,

    Attached to this post is a sample project illustrating the approach for creating the RadAjaxManager control dynamically described in the previous answer provided. Have a look at it and try following the logic there. Let me know what difference in your case.

    Additionally, note that in case you are adding the ajax setting dynamically, you can do it through the RadAjaxManager instead of creating RadAjaxManagerProxy control for that purpose.

    Sincerely yours,
    Iana
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. Dan Miller
    Dan Miller avatar
    23 posts
    Member since:
    Jul 2010

    Posted 26 Aug 2010 Link to this post

    Found out why the Ajax wasn't being triggered, my AjaxControlID was referencing the wrong contextmenu on the page!

    Thanks for the advice about not needing a RadAjaxManagerProxy though, I implemented that.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017