Possible to enable/disable ajaxmanager AjaxSettings vis javascript?

2 posts, 0 answers
  1. gunther
    gunther avatar
    95 posts
    Member since:
    Mar 2009

    Posted 03 Sep 2010 Link to this post

    I have a very complex RadGrid that is bound with a list that's stored in the session.  The grid's master table consists of one row per day in a given month, so it ranges from 28 to 31 rows.  Each grid item has 8 controls varying between native ASP controls to Telerik controls.  Each grid item also has a detail table which contains 3 gridbound columns with between 5 and 8 rows a piece.  As you can imagine, it's a pretty large grid.

    The issues we come across relate to speed with ajaxification.  We have the ajaxmanager set up as an AjaxSetting and one of the controls it updates is the radgrid (rgEmployees).  We have it set up this way because we have clientside script that calls the ajaxmanager using .ajaxRequest("RebindGrid") which ultimately results in the grid being rebound serverside.  Here's the declaration:

    <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
     <UpdatedControls>               
      <telerik:AjaxUpdatedControl ControlID="rgEmployees" LoadingPanelID="RadAjaxLoadingPanel1" />
      <telerik:AjaxUpdatedControl ControlID="OtherControls" />
      <telerik:AjaxUpdatedControl ControlID="OtherControls" />
      <telerik:AjaxUpdatedControl ControlID="OtherControls" />
     </UpdatedControls>
    </telerik:AjaxSetting>
               
    Here's where it gets hairy:  Each edit button, when clicked, calls .ajaxRequest("PopulateItem").  This takes the data from all the controls in the grid item and populates its cooresponding item in the session list on the server, after whice we use the ajax manager's ClientEvents-OnResponseEnd to invoke other javascript.  The issue is that, since the button also calls .ajaxRequest(), the entire grid goes through its harrowing update/re-rendering process when we click the button since the radgrid is an updated control of the ajax manager.

    Is there a way to modify the ajaxsettings/updated controls via client script?  We would want to do this so that we could disable it for when we click the edit button since we wouldn't need to update any controls, but would want to keep it since we would need to rerender the grid after a rebind.

    Conceptually, I would like to do something like this in javascript:

    var UpdatedControl = AjaxManager.GetAjaxSetting("RadAjaxManager1").GetUpdatedControl("rgEmployees");

    UpdatedControl.disable();
    AjaxManager.ajaxRequest("PopulateItem")
    UpdatedControl.enable();

    I obviously just made that up, but perhaps you can see where I am going with this.

    If necessary, I can create a sample app.  Due to the complexity of the grid, though, that could take some time, so I hope I explained myself good enough here.

  2. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 08 Sep 2010 Link to this post

    Hello gunther,

    The scenario you need to implement is not, by default, supported by RadAjaxManager. When it has updated controls and you are firing an .ajaxRequest(), the updated controls will always be refreshed. There is no way you can stop the grid from refreshing with .ajaxRequest().

    You can work around this scenario, though. You can use RadAjaxManager's ajaxRequestWithTarget() method to simulate an AJAX postback from, let's say, a hidden button. Thus, the button will fire its server-side Click event. You can use the buttons Click event handler to execute your custom server-side logic and the RadAjaxManager's OnResponseEnd client event will be fired OK, as you need. If you define an AJAX setting for your hidden button, you will make an AJAX request that will not update any content on the page.

    So, step by step:

    1. Define a hidden button on your page:

    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" style="display:none" />

    2. Use the button's OnClick event handler to execute your custom server logic:

    protected void Button1_Click(object sender, EventArgs e)
    {
        RadAjaxManager1.Alert("Button1_Click");
    }

    3. AJAX-ify the button to have it perform asynchronous requests:

    <telerik:AjaxSetting AjaxControlID="Button1">
        <UpdatedControls>
            <telerik:AjaxUpdatedControl ControlID="Button1" />
        </UpdatedControls>
    </telerik:AjaxSetting>

    4. Use RadAjaxManager's ajaxRequestWithTarget() method to fire an AJAX request from the button:

    var manager = $find('<%= RadAjaxManager.GetCurrent(Page).ClientID %>');
    manager.ajaxRequestWithTarget("Button1", "");

    Using this approach, you get a custom AJAX request that triggers some server-side processing without updating any HTML on the page.

    Veli
    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
Back to Top