Telerik is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting, .NET ORM , .NET CMS, Code Analysis, Mocking, Team Productivity and Automated Testing Tools. Building on its expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Telerik products help thousands of companies to be more productive and deliver reliable applications under budget and on time.
Version Q1 2012 released 04/11/2012
select

Ajax / Partial Ajaxification


Products:

Add to cartProductNameQuantityPerUnitUnitPriceUnitsInStock
 
Page size:
select
 30 items in 6 pages
Chai10 boxes x 20 bags$18.0039
Chang24 - 12 oz bottles$19.0017
Aniseed Syrup12 - 550 ml bottles$10.0013
Chef Anton's Cajun Seasoning48 - 6 oz jars$22.0053
Grandma's Boysenberry Spread12 - 8 oz jars$25.00120


Shopping cart:



  • The example demonstrates the ability of RadAjaxManager to ajaxify specific controls dynamically. Here, the ImageButtons are ajaxified intercepting the ItemCreated event hander of the grid.
    Here is a code snippet showing how this is achieved:

            protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) 
            { 
                if (e.Item is GridDataItem) 
                { 
                    GridDataItem dataItem = e.Item as GridDataItem; 
                    ImageButton ibtnAddToCart = (ImageButton)(dataItem["TemplateColumn1"]).FindControl("ibtnAddToCart"); 
                    RadAjaxManager1.AjaxSettings.AddAjaxSetting(ibtnAddToCart, RadGrid2); //ajaxify the button 
                } 
            } 

    When one of the image button is clicked, the corresponding item is added to the Shopping cart (RadGrid2).

    Both grids are ajaxafied with declaratively applied settings in the mark-up code. For further information please refer to the Default.aspx section.

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page Language="c#" CodeFile="DefaultCS.aspx.cs" Inherits="Telerik.Web.Examples.Ajax.PartialAjaxification.DefaultCS" %>

    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
    <%@ Register TagPrefix="qsf" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <%@ Register TagPrefix="sds" Namespace="Telerik.Web.SessionDS" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd">
    <html xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <qsf:HeadTag ID="Headtag1" runat="server" />
    </head>
    <body class="BODY">
        <form id="Form1" method="post" runat="server">
        <qsf:Header ID="Header1" runat="server" NavigationLanguage="c#" XhtmlCompliant="true"
            ShowSkinChooser="true" />
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="EmptyShoppingCart">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                        <telerik:AjaxUpdatedControl ControlID="RadGrid2" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
        </telerik:RadAjaxLoadingPanel>
        <telerik:RadFormDecorator ID="FormDecorator1" runat="server" DecoratedControls="Buttons">
        </telerik:RadFormDecorator>
        <%--RadGrid1--%>
        <br />
        <h5>Products:</h5>
        <hr />
        <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" AllowPaging="True"
            AllowSorting="True" GridLines="None" OnItemCreated="RadGrid1_ItemCreated" OnItemCommand="RadGrid1_ItemCommand"
            OnNeedDataSource="RadGrid1_NeedDataSource" PageSize="5">
            <MasterTableView AutoGenerateColumns="False" DataKeyNames="ProductID">
                <Columns>
                    <telerik:GridTemplateColumn UniqueName="TemplateColumn1" HeaderText="Add to cart"
                        AllowFiltering="false">
                        <ItemStyle HorizontalAlign="Center" />
                        <ItemTemplate>
    <asp:ImageButton ID="ibtnAddToCart" runat="server" ImageUrl="~/Ajax/Img/addtocart.gif"
    AlternateText="Add to cart" CommandName="AddToCart"/>

                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridBoundColumn DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName"
                        UniqueName="ProductName">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="QuantityPerUnit" HeaderText="QuantityPerUnit"
                        SortExpression="QuantityPerUnit" UniqueName="QuantityPerUnit">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="UnitPrice" DataType="System.Decimal" HeaderText="UnitPrice"
                        SortExpression="UnitPrice" UniqueName="UnitPrice" DataFormatString="{0:C}">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Units" DataType="System.Int32" HeaderText="UnitsInStock"
                        SortExpression="Units" UniqueName="Units" FooterAggregateFormatString="{0:C}">
                    </telerik:GridBoundColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>
        <br />
        <br />
        <h5>Shopping cart:</h5>
        <hr />
        <%--RadGrid2--%>
        <%--OnItemCreated="RadGrid2_ItemCreated" OnItemCommand="RadGrid2_ItemCommand"--%>
        <telerik:RadGrid ID="RadGrid2" runat="server" AllowFilteringByColumn="True" AllowPaging="True"
            ShowFooter="true" AllowSorting="True" GridLines="None" OnNeedDataSource="RadGrid2_NeedDataSource"
            PageSize="5">
            <MasterTableView AutoGenerateColumns="False" DataKeyNames="ProductID">
                <NoRecordsTemplate>
                    No products added to the shopping cart.
                </NoRecordsTemplate>
                <Columns>
                    <telerik:GridBoundColumn DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName"
                        UniqueName="ProductName">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="QuantityPerUnit" HeaderText="QuantityPerUnit"
                        SortExpression="QuantityPerUnit" UniqueName="QuantityPerUnit">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="UnitPrice" DataType="System.Decimal" HeaderText="UnitPrice"
                        SortExpression="UnitPrice" UniqueName="UnitPrice" DataFormatString="{0:C}">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Units" DataType="System.Int32" HeaderText="UnitsInCart"
                        SortExpression="Units" UniqueName="Units">
                    </telerik:GridBoundColumn>
                    <telerik:GridCalculatedColumn HeaderText="Total Price" UniqueName="TotalPrice" DataType="System.Double"
                      DataFields="UnitPrice, Units" Expression="{0}*{1}" Aggregate="Sum" DataFormatString="{0:C}"
                      FooterAggregateFormatString="Total : {0:C}">
                    </telerik:GridCalculatedColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>
        <div style="padding-top:5px; float:right">
    <asp:Button ID="EmptyShoppingCart" runat="server" Text="Empty Shopping cart"
    onclick="EmptyShoppingCart_Click" />

        </div>
        <br />
        <qsf:Footer runat="server" ID="Footer1" />
        </form>
    </body>
    </html>

Get more than expected!

Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.

Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Copyright 2002-2012 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451