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

How to handle AJAX requests for nested controls

1 Answer 40 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Condorito asked on 30 Mar 2011, 05:15 PM
Hi,  I have a PanelBar with one RadPanelItem, which has  an itemtemplate with a RadGrid inside. Outside of the PanelBar, I have a treeview.  The behavior I want is that when an item is selected under the treeview, it causes an AJAX request that refreshes the RadGrid only inside the RadPanelItem with new data based on the treeview item the user selected without causing a full postback. 

The way I'm trying to get this to work is by capturing the onClientNodeClicking of the Treeview, I then attempt a ajaxManager.ajaxRequest call, and I can see that server-side code is executed, but for some reason nothing changes after it's done, which leads me to believe that I'm not doing something right.

Here's simplified code of what I'm trying to do:

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<head runat="server">
    <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
<script language="javascript" type="text/javascript">
    function clientNodeClicking(sender, args) {
    function clientNodeChecking(sender, args) {
   function refreshGrid(args) {
    function InitiateAsyncRequest(arguments) {
        var ajaxManager = $find("<%= ramNotification.ClientID %>");
    <form id="form1" runat="server">
       <telerik:RadScriptManager ID="rsmMain" runat="server">
       <telerik:RadAjaxManager ID="ramNotification" runat="server">
      <telerik:RadPanelbar ID="rpbContactType" runat="server" Width="100%" ExpandMode="FullExpandedItem" Height="275" >
                <telerik:RadPanelItem Text="Address Book" Value="MainRadPanel"  Expanded="true" Selected="true">
                        <telerik:RadPanelItem Value="AddressBook">
                              <telerik:RadGrid ID="rgAddressBook" runat="server" Width="100%" Height="225" AllowMultiRowSelection="true" >
                                    <ClientSettings EnableRowHoverStyle="true" AllowDragToGroup="false" AllowGroupExpandCollapse="false">
                                        <Scrolling AllowScroll="True" UseStaticHeaders="true" ScrollHeight="225" />
                                            <Selecting AllowRowSelect="true" />
                                    <MasterTableView AutoGenerateColumns="false"  CommandItemDisplay="None" ClientDataKeyNames="ID, Address" DataKeyNames="ID, Address">
                                            <telerik:GridBoundColumn DataField="ID" Display="false" UniqueName="ID"></telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="AddressName" HeaderText="Name" HeaderStyle-Width="150" ItemStyle-Width="150" ></telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="Address" HeaderText="Address"></telerik:GridBoundColumn>
         <telerik:RadTreeView ID="rtvCategories" runat="server"
           OnClientNodeClicking = "clientNodeClicking"
            OnClientNodeChecking = "clientNodeChecking"
                <telerik:RadTreeNode Value="0" Text="First Item" />
                <telerik:RadTreeNode Value="1" Text="Second Item" />

Public rgAddressBook As Telerik.Web.UI.RadGrid
    Private _IDSelected As Integer = 0
    Private Sub StatusNotificationsTest_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        rgAddressBook = rpbContactType.FindItemByValue("MainRadPanel").Items.FindItemByValue("AddressBook").FindControl("rgAddressBook")
    End Sub
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Page.IsPostBack = False Then
            rgAddressBook.DataSource = GetRadGridData(_IDSelected)
        End If
    End Sub
    Protected Sub rgAddressBook_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs)
        rgAddressBook.DataSource = GetRadGridData(_IDSelected)
    End Sub
    Private Function GetRadGridData(ByVal ItemSelected As Integer) As DataTable
        GetRadGridData = New DataTable
        With GetRadGridData
            .Columns.Add("ID", GetType(Integer))
            .Columns.Add("AddressName", GetType(String))
            .Columns.Add("Address", GetType(String))
        End With
        Dim NewRow As DataRow = GetRadGridData.NewRow
        Select Case ItemSelected
            Case 0
                NewRow("ID") = "0"
                NewRow("AddressName") = "John Doe"
                NewRow("Address") = ""
            Case 1
                NewRow("ID") = "1"
                NewRow("AddressName") = "John Smith"
                NewRow("Address") = ""
        End Select
    End Function
    Protected Sub ramNotification_AjaxRequest(ByVal sender As Object, ByVal e As Telerik.Web.UI.AjaxRequestEventArgs) Handles ramNotification.AjaxRequest
        Dim argument As String = e.Argument
        _IDSelected = argument
    End Sub

Is there an example somewhere for something similar?

1 Answer, 1 is accepted

Sort by
Dimitar Terziev
Telerik team
answered on 05 Apr 2011, 09:18 AM
Hello Juan,

The problem seems to be related to the fact that you are not referencing the RadGrid properly. Since it's nested in the item template of the PanelBar item, you should reference it as described in the help article here.

Best wishes,
Dimitar Terziev
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
Asked by
Top achievements
Rank 1
Answers by
Dimitar Terziev
Telerik team
Share this question