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

2 user controls on an aspx page

2 Answers 278 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Helen
Top achievements
Rank 1
Helen asked on 27 Mar 2014, 09:01 PM
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 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 28 Mar 2014, 05:30 AM
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.
0
Helen
Top achievements
Rank 1
answered on 28 Mar 2014, 12:18 PM
Shinu,

Thank you, the sample helps me much better!!

Helen
Tags
Ajax
Asked by
Helen
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Helen
Top achievements
Rank 1
Share this question
or