You want to create an event in the control that the parent element is subscribing to. See OdeToCode for an example.
Here is an article for longevity:
, , , , - . . , - . - , .
" ", , ( ) , , (), , .
.
<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="WebUserControl1.ascx.cs"
Inherits="aspnet.eventbubble.WebUserControl1"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"
%>
<asp:Panel id="Panel1" runat="server" Width="128px" Height="96px">
WebUserControl1
<asp:Button id="Button1" Text="Button" runat="server"/>
</asp:Panel>
.
public class WebUserControl1 : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Panel Panel1;
private void Page_Load(object sender, System.EventArgs e)
{
Response.Write("WebUserControl1 :: Page_Load <BR>");
}
private void Button1_Click(object sender, System.EventArgs e)
{
Response.Write("WebUserControl1 :: Begin Button1_Click <BR>");
OnBubbleClick(e);
Response.Write("WebUserControl1 :: End Button1_Click <BR>");
}
public event EventHandler BubbleClick;
protected void OnBubbleClick(EventArgs e)
{
if(BubbleClick != null)
{
BubbleClick(this, e);
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
(BubbleClick), . , BubbleClick, EventHandler - , EventHandler, Click.
OnBubbleClick , - (BubbleClick!= null), , BubbleClick, EventArgs () . , Response.Write, .
ASPX .
<%@ Register TagPrefix="ksa"
TagName="BubbleControl"
Src="WebUserControl1.ascx"
%>
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="aspnet.eventbubble.WebForm1"
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<ksa:BubbleControl id="BubbleControl" runat="server" />
</form>
</body>
</HTML>
.
public class WebForm1 : System.Web.UI.Page
{
protected WebUserControl1 BubbleControl;
private void Page_Load(object sender, System.EventArgs e)
{
Response.Write("WebForm1 :: Page_Load <BR>");
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
BubbleControl.BubbleClick += new EventHandler(WebForm1_BubbleClick);
}
#endregion
private void WebForm1_BubbleClick(object sender, EventArgs e)
{
Response.Write("WebForm1 :: WebForm1_BubbleClick from " +
sender.GetType().ToString() + "<BR>");
}
}
, InitializeComponent. , Reponse.Write, .
: , InitializeComponent, , - , .