2 user controls on an aspx page

3 posts, 0 answers
  1. Helen
    Helen avatar
    42 posts
    Member since:
    Nov 2013

    Posted 27 Mar 2014 Link to this post

    Hi,

    I've been reading through your help doc and also searched through the forum on how to pass parameter from one user control (UC1) to another user control (UC2), but still not quite getting it, hopefully you could help me understand it better.

    I created a small project as below:

    My aspx page contains UC1 (a grid) and UC2 (a textbox).  When UC1 gets clicked, it'll get the location id and I need to pass that value to UC2 to display it.
    RadAjaxManager is on the aspx page and RadAjaxManagerProxy is set up in each user controls.

    The closest I can find is this from your help doc :

    http://www.telerik.com/help/aspnet-ajax/ajax-load-control-from-another-webusercontrol-in-different-masterpage-contentplaceholder.html

    Is this the way I should follow to send data from one user control to another by using bubble event or is there another way you would recommend?

    Thank you,

    Helen
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 28 Mar 2014 in reply to Helen Link to this post

    Hi Helen,

    The event bubbling approach will use if we load a user control dynamically from an action in another loaded user control. If you are loading second user control dynamically from first user control then please follow the event bubbling approach. Please have a look into the sample code snippet where I am loading both of the UserControl statically and accessing one user control from another.

    ASPX:
    <uc1:Grid ID="Grid1" runat="server" />
    <uc2:TextBox ID="TextBox1" runat="server" />
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    </telerik:RadAjaxManager>

    Grid.ASCX:
    <telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadTextBox1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManagerProxy>
    <telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
        OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged">
        <ClientSettings EnablePostBackOnRowClick="true" Selecting-AllowRowSelect="true">
        </ClientSettings>
    </telerik:RadGrid>

    Grid.ASCX.CS:
    protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        var departments = new[] {
                new { DeptID = 1, Abbr = "ACME", Name = "ACME Corporation" },
                new { DeptID = 2, Abbr = "MSFT", Name = "Microsoft Corporation" },
                new { DeptID = 3, Abbr = "GOOG", Name = "Google, Inc" }
            };
        RadGrid1.DataSource = departments;
    }
    protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
    {
        //code for acceessing the grid data item
        UserControl control = (UserControl)Page.FindControl("TextBox1"); //id of the usercontrolpage
        RadTextBox textbox = (RadTextBox)control.FindControl("RadTextBox1"); //id of the RadTextBox
        //your code for updating the value of the textbox
    }

    TextBox.ASCX:
    <telerik:RadTextBox ID="RadTextBox1" runat="server" Text="dd">
    </telerik:RadTextBox>

    Let me know if you have any concern.
    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Helen
    Helen avatar
    42 posts
    Member since:
    Nov 2013

    Posted 28 Mar 2014 in reply to Shinu Link to this post

    Shinu,

    Thank you, the sample helps me much better!!

    Helen
Back to Top