New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Update TargetControls with AJAX

ProductSupplierPrice
Page size:
10
14 Tofu Mayumi's$23.25
15 Genen Shouyu Mayumi's$15.50
17 Alice Mutton Pavlova, Ltd.$39.00
18 Carnarvon Tigers Pavlova, Ltd.$62.50
19 Teatime Chocolate Biscuits Specialty Biscuits, Ltd.$9.20
20 Sir Rodney's Marmalade Specialty Biscuits, Ltd.$81.00
21 Sir Rodney's Scones Specialty Biscuits, Ltd.$10.00
22 Gustaf's Knäckebröd PB Knäckebröd AB$21.00
23 Tunnbröd PB Knäckebröd AB$9.00
24 Guaraná Fantástica Refrescos Americanas LTDA$4.50

There are situations when the RadToolTipManager's TargetControls collection should be updated. This example shows a common scenario when this should be done - it contains a RadGrid which has its paging and sorting turned on. Every time a page is changed or the grid is sorted, it is updated through AJAX and the RadToolTipManager's TargetControls collection should get updated, too. In order to achieve this, both the grid and the RadToolTipManager are ajaxified by using a RadAjaxManager control.

Note, that when the page index is changed, or a sorting has been done, the RadToolTipManager's TargetControls collection is cleared because the records on the new grid's page have the same ClientIDs as the old ones.

Move the mouse over a product name to see more details about it
  • DefaultCS.aspx
  • ProductDetailsCS.ascx
  • DefaultCS.aspx.cs
    • DefaultCS.aspx.cs
    • ProductDetailsCS.ascx.cs
  • styles.css
<%@ Page Language="c#" CodeFile="DefaultCS.aspx.cs" EnableViewStateMac="false" ViewStateEncryptionMode="Never"Inherits="Telerik.Web.Examples.ToolTip.TargetControlsAndAjax.DefaultCS"  %>

<%@ Register Src="ProductDetailsCS.ascx" TagName="ProductDetails" TagPrefix="uc1" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head runat="server">
    <title>Telerik ASP.NET Example</title>
    <link rel="Stylesheet" href="styles.css" />
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
    <div class="demo-container size-medium">
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
                        <telerik:AjaxUpdatedControl ControlID="RadToolTipManager1"></telerik:AjaxUpdatedControl>
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
        </telerik:RadAjaxLoadingPanel>
        <telerik:RadToolTipManager RenderMode="Lightweight" ID="RadToolTipManager1" OffsetY="-1" HideEvent="ManualClose"
            Width="250" Height="350" runat="server" OnAjaxUpdate="OnAjaxUpdate" RelativeTo="Element"
            Position="MiddleRight">
        </telerik:RadToolTipManager>
        <telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1"
            GridLines="None" OnItemDataBound="RadGrid1_ItemDataBound" AllowPaging="true"
            AllowSorting="true" PageSize="10" OnItemCommand="RadGrid1_ItemCommand">
            <MasterTableView AutoGenerateColumns="False" CommandItemDisplay="None" CurrentResetPageIndexAction="SetPageIndexToFirst"
                DataKeyNames="ProductID" DataSourceID="SqlDataSource1" Dir="LTR" Frame="Border"
                TableLayout="Auto">
                <Columns>
                    <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="ProductID" Display="false"
                        DataType="System.Int32" FilterListOptions="VaryByDataType" ForceExtractValue="None"
                        HeaderText="ProductID" ReadOnly="True" SortExpression="ProductID" UniqueName="ProductID">
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn HeaderText="Product" SortExpression="ProductName">
                        <ItemTemplate>
                            <asp:HyperLink ID="targetControl" runat="server" NavigateUrl="#" Text='<%# Eval("ProductName") %>'></asp:HyperLink>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridBoundColumn AllowSorting="true" DataField="CompanyName" HeaderText="Supplier"
                        SortExpression="CompanyName" UniqueName="CompanyName">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn AllowSorting="true" DataField="UnitPrice" DataFormatString="{0:C}"
                        HeaderText="Price" SortExpression="UnitPrice">
                    </telerik:GridBoundColumn>
                </Columns>
                <EditFormSettings>
                    <EditColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType">
                    </EditColumn>
                </EditFormSettings>
                <PagerStyle PageSizeControlType="RadDropDownList" ShowPagerText="false" />
            </MasterTableView>
        </telerik:RadGrid>
    </div>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [Products] INNER JOIN [Suppliers] ON Products.SupplierID=Suppliers.SupplierID "></asp:SqlDataSource>
    </form>
</body>
</html>

Support & Learning Resources

Find Assistance