Ajaxify User Control w/ RadControl Outside of User Control

4 posts, 0 answers
  1. Rob
    Rob avatar
    116 posts
    Member since:
    Aug 2012

    Posted 19 Feb 2010 Link to this post

    I've searched and search and can't quite find an example like I'm looking for.  Here's my situation and I'll keep it as simple as possible:

    I have a RadToolbar and a user control on a page.  The user control has a RadGrid in it.  When I click a button on the RadToolbar, I want to ajaxify the user control (no screen flash / reload).  The grid gets populated in the NeedDataSource() event by pulling it's data from a session variable that was populated in the button click event..  Really all I need to know is how to wire this up. If a simple example could be provided, that would be great.  Like I already said, I've searched the forums, online demos, & help file.

    Thanks,
    Rob
  2. Rob
    Rob avatar
    116 posts
    Member since:
    Aug 2012

    Posted 19 Feb 2010 Link to this post

    OK, here's the code to provide a starting point.  I simplified the scenario even more by just using an <asp:button> instead of a RadToolbar.

    What I'm noticing is, the first time I click the button nothing happens.  The 2nd time I click the button, I get my desired results.  How do I get it to work on the first click?

    default.aspx

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> 
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
    <%@ Register Src="ucAjaxifyMe.ascx" TagName="ucLabel" TagPrefix="MyCompany" %> 
    <html xmlns="http://www.w3.org/1999/xhtml">  
    <head runat="server">  
        <title></title>  
    </head> 
    <body> 
        <form id="form1" runat="server">  
        <div> 
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server">  
            </telerik:RadScriptManager> 
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
                <AjaxSettings> 
                    <telerik:AjaxSetting AjaxControlID="btn">  
                        <UpdatedControls> 
                            <telerik:AjaxUpdatedControl ControlID="ucAjaxifyMe1" /> 
                        </UpdatedControls> 
                    </telerik:AjaxSetting> 
                </AjaxSettings> 
            </telerik:RadAjaxManager> 
            <asp:Button ID="btn" runat="server" Text="Button" /> 
            <MyCompany:ucLabel ID="ucAjaxifyMe1" runat="server" /> 
        </div> 
        </form> 
    </body> 
    </html> 

    default.aspx.vb

    Imports System.Data  
    Partial Class _Default  
        Inherits System.Web.UI.Page  
        Protected Sub btn_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles btn.Click  
            Session("DataTable") = CreateDT()  
        End Sub 
        Private Function CreateDT() As datatable  
            Dim dt As New DataTable  
            Dim col As New DataColumn  
            col.ColumnName = "Field1" 
            dt.Columns.Add(col)  
            Dim dr As DataRow = dt.NewRow  
            dr("Field1") = "Row1" 
            dt.Rows.Add(dr)  
            dr = dt.NewRow  
            dr("Field1") = "Row2" 
            dt.Rows.Add(dr)  
            Return dt  
        End Function 
    End Class 
     

    ucAjaxifyMe.ascx

    <%@ Control Language="VB" AutoEventWireup="false" CodeFile="ucAjaxifyMe.ascx.vb" Inherits="ucAjaxifyMe" %>    
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>    
    <telerik:RadGrid ID="RadGrid1" runat="server"></telerik:RadGrid>    
     
     

    ucAjaxifyMe.ascx.vb

    Imports System.Data  
    Partial Class ucAjaxifyMe  
        Inherits System.Web.UI.UserControl  
        Protected Sub RadGrid1_NeedDataSource(ByVal source As ObjectByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource  
            If Session("DataTable") IsNot Nothing Then 
                Me.RadGrid1.DataSource = CType(Session("DataTable"), DataTable)  
            End If 
        End Sub 
    End Class 
     
  3. Rob
    Rob avatar
    116 posts
    Member since:
    Aug 2012

    Posted 22 Feb 2010 Link to this post

    I could really use some help on this.
  4. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 23 Feb 2010 Link to this post

    Hi Dudeman,

    In order the grid to display the data you are retrieving on a button Click, you need to explicitly rebind it. Please find attached a sample project illustrating the above suggestion and let me know if it works for you.

    Greetings,
    Iana
    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.
Back to Top