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

Updating individual controls with AjaxManager

3 Answers 173 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Pavlek
Top achievements
Rank 1
Pavlek asked on 24 Mar 2009, 11:37 PM
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

3 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 30 Mar 2009, 08:34 AM
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.
0
Michael Ward
Top achievements
Rank 1
answered on 31 Mar 2009, 05:23 AM
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


0
Sebastian
Telerik team
answered on 02 Apr 2009, 12:13 PM
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.
Tags
Ajax
Asked by
Pavlek
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Michael Ward
Top achievements
Rank 1
Share this question
or