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

Ajaxification with nested master page hierarchies

2 Answers 85 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 28 Jan 2009, 07:53 PM

I am working on a large scale web application with a nested master page hierarchy.  What I am trying to do is server side ajaxification.  In other words, i want the same functionality as a ScirptManagerProxy, only not in the markup, but via a function that I will store in the Page's base class.  The master page that contains the script manager is 3 levels up from the current master page that my content page is using.  I've tried the RadAjaxManager.GetCurrent(Page) method, but since it lives so far down the master page chain, IT hasn't been created yet.  I have created a function that will crawl back through the nesting to find me the master page i am looking for.  I have also created a public property on the master page to expose the ajax manager.

Here's the root master page code behind:

public partial class Shell : MasterPage  
{  
    public RadAjaxManager AjaxManager  
    {  
        get { return ajaxMgr; }  
    }  


Here's what my current layout looks like:

Shell.master
    -->  LeftSideAndContent.master
        --> LeftNavigationAndContent.master
            -->  ContentPage.aspx

After doing some research (using Reflector), i found that master pages are actually created in the getter of Page.Master, so simply casting ContentPage's Master as (Shell) doesn't work, and returns a null reference of the script Manger.  The master can be referenced correctly by using this.Master.Master.Master, but this is bad design, as it will break if our layout adds or subtracts layout master pages.  To alleviate this problem, I created the following generic function on my content page's base class:

public abstract class ContentPageBase : System.Web.UI.Page  
{  
    public static T FindMasterPage<T>(Page page) where T : MasterPage  
    {  
        Type type = typeof(T);  
        MasterPage master = page.Master;  
 
        while (master != null)  
        {  
            if (master.GetType().BaseType == type)  
            {  
                break;  
            }  
 
            master = master.Master;  
        }  
 
        return (T)master;  
    }  

What this allows me to do is is get a hook to the actual RadAjaxManager that exists up the chain in the following way:

            AjaxSetting setting = new AjaxSetting(uxCategoryGrid.ClientID);  
            setting.UpdatedControls.Add(new AjaxUpdatedControl(uxCategoryGrid.ClientID, ""));  
            ContentPageBase.FindMasterPage<Shell>(this).AjaxManager.AjaxSettings.Add(setting);  
 

After all this, I am still having an issue with the loading panel not popping up when I muck with the grid.  Am I missing something here?  I know that the master Page_Load fires AFTER the content Page_Load, so could the master page be annihilating the controls of the AjaxManager even after it gets hydrated in the function?

Ideally, what I am looking for is the easiest way to accomplish the following: 

public partial class ContentPage : ContentPageBase  
{  
    protected void Page_Load(object sender, EventArgs e)  
    {  
        this.Ajaxify(uxCategoryGrid);  
    }  

Any help will be appreciated.

Paul

2 Answers, 1 is accepted

Sort by
0
Paul
Top achievements
Rank 1
answered on 28 Jan 2009, 10:26 PM
I had an utter facepalm moment as I found the solution.

Due to the fact that RadScriptManager and RadScriptManagerProxy are design time tools (this is at least true for the proxy), i need to reference the controls by their ID, and not ClientID.

I've been running in circles for days.  Now, I have my "Ajaxification" one-liner.

I added a function to the Shell master page that added the control to the RadAjaxManager, and corrected the ClientID problem
        public void AjaxifyControl(Control control)  
        {  
            AjaxSetting setting = new AjaxSetting(control.ID);  
            setting.UpdatedControls.Add(new AjaxUpdatedControl(control.ID, ""));  
            this.AjaxManager.AjaxSettings.Add(setting);  
        } 


and here's my one-liner method. 

 
 
ContentPageBase.FindMasterPage<Shell>(this).AjaxifyControl(uxCategoryGrid);  
 
 


and call it via page_load or page_init on the content page.

Enjoy!
0
Sebastian
Telerik team
answered on 29 Jan 2009, 08:02 AM
Hi Paul,

I am glad that you discovered a solution which suits your needs - thank you for posting it in this public forum thread. Thus you can help other community members which search similar type of functionality. I updated your Telerik points for the involvement.

Best regards,
Sebastian
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Ajax
Asked by
Paul
Top achievements
Rank 1
Answers by
Paul
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or