As mentioned this is bad design. The user control should accept a value, and you can then "do work" when that value is set, or when a method on it is called etc. The aspx page is the parent and the control is the child, and interaction should be one way; the parent controls the child, the child doesn't control the parent. This allows your control to sit happily on any page, even one without the desired combo. If you want any kind of child->parent communication that is done using events, and that way the parent cab choose to subscribe to what they are interested in, and again your control will work on any page.
Attach.ascx.cs
public partial class Attach : System.Web.UI.UserControl
{
public string Text { get; set; }
public delegate void MyProcessHandler(string data);
public event MyProcessHandler MyProcess;
public void DoSomething(int x)
{
string data = Text + " " + (x * 2).ToString();
if (MyProcess != null)
{
MyProcess(data);
}
}
}
Page;
<asp:DropDownList ID="DropDownData" runat="server">
<asp:ListItem Text="One" Value="1" />
<asp:ListItem Text="Two" Value="2" />
<asp:ListItem Text="Three" Value="3" />
</asp:DropDownList>
<ctl:Attach ID="Attach1" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Click" OnClick="Button1_Click" />
<asp:Label ID="Label1" runat="server" />
protected void Button1_Click(object sender, EventArgs e)
{
Attach1.MyProcess += new Attach.MyProcessHandler(Attach1_MyProcess);
Attach1.Text = DropDownData.SelectedValue;
Attach1.DoSomething(int.Parse(Attach1.Text));
}
protected void Attach1_MyProcess(string data)
{
Label1.Text = data;
}