Updating individual controls with AjaxManager

4 posts, 0 answers
  1. Pavlek
    Pavlek avatar
    8 posts
    Member since:
    Jun 2007

    Posted 24 Mar 2009 Link to this post

    Hi,

    I’m upgrading our solution from the classic controls to the Ajax.Net controls and have a problem with the following scenario:
    On one page, I have several user controls which each have a grid that I want to refresh individually, from a js call.
    With the old controls, I would just enable Ajax for the grid and then do Ajax requests like this
    window['<%=grid.ClientID%>'].AjaxRequest('<%=this.UniqueID%>', args); 

    Now, I only have one Ajax manager, so in the user control I get a reference and then subscribe to the AjaxRequest event. To get the grid to refresh I have to add ajax settings.
    RadAjaxManager manager = RadAjaxManager.GetCurrent(Page); 
    manager.AjaxRequest += manager_AjaxRequest; 
    manager.AjaxSettings.AddAjaxSetting(manager, grid); 

    This works fine, in the manager_AjaxRequest function I check the argument and only do something if it is the right request.
    But since I added the grid to the AjaxSettings it will get updated on the client every time, even if it doesn’t have to. So if I only want grid A to upgrade how do I prevent Grid B from updating as well? Both subscribe to the same AjaxRequest event and both need to have AjaxSettings.
    A workout I found is using a hidden button and then using the ajaxRequestWithTarget to pretend the button was causing the update, but there must be a better way to do it.
    Any help on this would be appreciated.
    Cheers
  2. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 30 Mar 2009 Link to this post

    Hello Pavlek,

    Indeed if you use the RadAjaxManager as an initiator of the ajax request, both grid instances will be updated on each submit made through the manager.

    It seems that you found a method to determine the control which starts the request using a hidden button on the page. Another option would be to pass the grid client id as a first argument to the ajaxRequestWithTarget client method (see the bottom section of this help topic for details) and then check this id on the server intercepting the RaisePostBackEvent handler of the page/implementing it in case the grid resides inside user control.

    Best regards,
    Sebastian
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Michael Ward
    Michael Ward avatar
    6 posts
    Member since:
    Jul 2006

    Posted 31 Mar 2009 Link to this post

    Hi Sebastian,

    thanks for your reply.
    I tried the approach using ajaxRequestWithTarget as well, but the RaisePostBackEvent is never raised in my control.

    $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequestWithTarget('<%= grid.ClientID %>', args); 

    Regards,
    Michael


  5. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 02 Apr 2009 Link to this post

    Hello Michael,

    You need to use the UniqueID of the grid as first argument of the ajaxRequestWithTarget method to ensure that it will be identified correctly when triggering the postback request from any naming container. Here is the code from a quick test I made locally which worked as expected:

               <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"
     
                    <script type="text/javascript"
                        function TriggerRequest(sender, eventArgs) 
                        { 
                          $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequestWithTarget('<%= grid.UniqueID %>', eventArgs.get_itemIndexHierarchical()); 
                        } 
             
                    </script> 
     
                </telerik:RadCodeBlock> 
                <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
                <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"
                    <AjaxSettings> 
                        <telerik:AjaxSetting AjaxControlID="grid"
                            <UpdatedControls> 
                                <telerik:AjaxUpdatedControl ControlID="grid" /> 
                            </UpdatedControls> 
                        </telerik:AjaxSetting> 
                    </AjaxSettings> 
                </telerik:RadAjaxManager> 
                <telerik:RadGrid ID="grid" runat="server" DataSourceID="SqlDataSource1" AllowSorting="True" 
                    GridLines="None"
                    <ClientSettings> 
                        <ClientEvents OnRowClick="TriggerRequest" /> 
                    </ClientSettings> 
                </telerik:RadGrid> 
                <asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" 
                    ProviderName="System.Data.SqlClient" SelectCommand="SELECT TOP 20 CustomerID, CompanyName, ContactName, ContactTitle, Address, PostalCode FROM Customers" 
                    runat="server"></asp:SqlDataSource> 

        Protected Overrides Sub RaisePostBackEvent(ByVal source As IPostBackEventHandler, ByVal eventArgument As String
            MyBase.RaisePostBackEvent(source, eventArgument) 
            RadAjaxManager1.ResponseScripts.Add("alert('Clicked row index is: " & eventArgument.ToString() & "')"
        End Sub 

    The index of the clicked row should be output when clicking an arbitrary item in the grid. I am attaching my sample project for further reference.

    Kind regards,
    Sebastian
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Back to Top