This is a migrated thread and some comments may be shown as answers.

Dynamic RadAjaxManager/RadAjaxManagerProxy

8 Answers 154 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Dan Miller
Top achievements
Rank 1
Dan Miller asked on 07 Aug 2010, 12:45 AM
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.

8 Answers, 1 is accepted

Sort by
0
Dan Miller
Top achievements
Rank 1
answered on 10 Aug 2010, 08:22 PM
Ideas anyone?
0
Maria Ilieva
Telerik team
answered on 11 Aug 2010, 02:28 PM
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
0
Dan Miller
Top achievements
Rank 1
answered on 11 Aug 2010, 07:18 PM
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.
0
Dan Miller
Top achievements
Rank 1
answered on 20 Aug 2010, 01:00 AM
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.
0
Iana Tsolova
Telerik team
answered on 25 Aug 2010, 12:56 PM
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
0
Dan Miller
Top achievements
Rank 1
answered on 25 Aug 2010, 06:32 PM
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);
            }
            /*********************************************************/
        }
0
Iana Tsolova
Telerik team
answered on 26 Aug 2010, 01:57 PM
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
0
Dan Miller
Top achievements
Rank 1
answered on 26 Aug 2010, 09:48 PM
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.
Tags
Ajax
Asked by
Dan Miller
Top achievements
Rank 1
Answers by
Dan Miller
Top achievements
Rank 1
Maria Ilieva
Telerik team
Iana Tsolova
Telerik team
Share this question
or