Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would expose the child DropDownList's <code>OnSelectedItemChanged</code> event AND the actual DropDownList at the top public level for the user control. </p> <p>This would allow you to catch the <code>OnSelectedItemChanged</code> event in the <code>Page</code> and set the value of the second user control.</p> <p>Let me know if you want some sample code. </p> <p>Ok, so first the user control</p> <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SampleUserControl.ascx.cs" Inherits="WebApplication1.UserControls.SampleUserControl" %&gt; &lt;asp:DropDownList runat="server" ID="DdlTest" AutoPostBack="true"&gt; &lt;asp:ListItem Text="Sampe 1" /&gt; &lt;asp:ListItem Text="Sampe 2" /&gt; &lt;/asp:DropDownList&gt; </code></pre> <p>now the file behind that</p> <pre><code>public partial class SampleUserControl : System.Web.UI.UserControl { public DropDownList InternalDropDownList { get { return DdlTest; } } protected void Page_Load(object sender, EventArgs e) { } } </code></pre> <p>okay, lets go to the actual .aspx</p> <pre><code>&lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;uc1:SampleUserControl ID="SampleUserControl1" runat="server" /&gt; &lt;uc1:SampleUserControl ID="SampleUserControl2" runat="server" /&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p>and the code behind that</p> <pre><code>public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { SampleUserControl1.InternalDropDownList.SelectedIndexChanged += InternalDropDownList_SelectedIndexChanged; } void InternalDropDownList_SelectedIndexChanged(object sender, EventArgs e) { SampleUserControl2.InternalDropDownList.SelectedValue = SampleUserControl1.InternalDropDownList.SelectedValue; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload