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

Updating a master page control from a control within a content area

2 Answers 160 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Josh Anderson
Top achievements
Rank 1
Josh Anderson asked on 02 Feb 2009, 08:49 PM
I have a master page set up with a RadAjaxManager, some controls, and a content placeholder.  I have wired up a few buttons to a RadTreeView that exists on the master page, and ajax updates are occurring as expected.  I have also used RadAjaxManagerProxy to successfully ajax-enable a grid that resides in the content page.

What I have not been able to do is configure the content page so that I can trigger an update to the treeview on the master page.  Here's what I've done so far:

  1. I have exposed a public method on the master page called BuildHierarchy() which populates the treeview.
  2. I have a button in the content page that calls the BuildHierarchy() method after changing some data.
  3. I have programmatically added the ajax settings that I thought would allow the AjaxManager to allow that update.

Below is the key piece code I've used to try to set up the scenario described above.  The buttonMakeDemo control is a button which I need to update the RadGrid within the content page and the RadTreeView in the master page.

First, the relevant ajax code in my ASPX page.  I'm allowing the grid to be ajax-enabled for sorting, and I'm allowing the button to update the grid:

    <telerik:RadAjaxManagerProxy ID="radajaxProxy" runat="server"
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="gridMGs"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="gridMGs" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
            <telerik:AjaxSetting AjaxControlID="buttonMakeDemo"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="gridMGs" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManagerProxy> 

Next, the relevant codebehind in the content page.  You can see that I've also tried adding the settings to the RadAjaxManagerProxy's AjaxSettings, but that doesn't work either.

var ajaxManager = RadAjaxManager.GetCurrent(Page); 
var treeviewHierarchy = (RadTreeView) Master.FindControl("treeviewHierarchy"); 
// radajaxProxy.AjaxSettings.AddAjaxSetting(buttonMakeDemo, treeviewHierarchy); 
ajaxManager.AjaxSettings.AddAjaxSetting(buttonMakeDemo, treeviewHierarchy); 

In case it matters, here's the codebehind for the button click event.  "ThreePaneMaster" is the class name of the master page in question.  Don't worry about the argument passed to that BuildHierarchy method -- it's a business object accessible on the page.

protected void buttonMakeDemo_Click(object sender, EventArgs e) 
    // Do my business logic stuff here 
             
    gridMGs.Rebind(); 
    ((ThreePaneMaster) Master).BuildHierarchy(RootSecurityToken.AccountID); 

Any ideas what I might be doing wrong?  The ajax-enabled controls work so long as they're all either in the master or in the content, but not if one's in the content and one's in the master.

Thanks,
Josh

2 Answers, 1 is accepted

Sort by
0
Josh Anderson
Top achievements
Rank 1
answered on 02 Feb 2009, 09:32 PM
I believe I solved my problem, but I want to make sure I'm not creating unnecessary ajax traffic.  What I did was add the ContentPlaceHolder control as an ajax-enabled control.  Here's the relevant updated code:

    <telerik:RadAjaxManager ID="ajaxmanagerMain" runat="server"
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="buttonHierarchySearch"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="treeviewHierarchy" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
            <telerik:AjaxSetting AjaxControlID="buttonClearHierarchySearch"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="treeviewHierarchy" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
            <telerik:AjaxSetting AjaxControlID="checkboxShowInactives"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="treeviewHierarchy" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
            <telerik:AjaxSetting AjaxControlID="MainPaneContent"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="treeviewHierarchy" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManager> 

The last set of ajax settings is the key piece.

This isn't going to create excessive updating traffic, will it?

Josh
0
Pavlina
Telerik team
answered on 05 Feb 2009, 06:31 PM
Hello Josh,

You should be calm that you are not creating excessive traffic.

Regarding your previous question:
You need to add AJAX pair dynamically and  you should always do this in a Page event handler, which is executed each time during the page lifecycle (Page_Load, Page_PreRender) so that the control could be ajaxified when the page is initially loaded.

Regards,
Pavlina
the Telerik team

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