UseWebusercontrolWhen creating a control, the event definition method is as follows:
Controls:
<% @ Control Language = "C #" autoeventwireup = "true" codefile = "supercontrol. ascx. cs" inherits = "supercontrol" %>
<Div>
<Asp: textbox id = "textbox1" runat = "server"> </ASP: textbox>
</Div>
<Div>
<Asp: dropdownlist id = "dropdownlist1" runat = "server" autopostback = "true" ontextchanged = "dropdownlist1_textchanged">
<Asp: listitem> 1 </ASP: listitem>
<Asp: listitem> 2 </ASP: listitem>
<Asp: listitem> 3 </ASP: listitem>
<Asp: listitem> 4 </ASP: listitem>
</ASP: dropdownlist>
</Div>
Background:
Public partial class supercontrol: system. Web. UI. usercontrol
{
Public event eventhandler textchanged;//Event Delegate
Protected void dropdownlist1_textchanged (Object sender, eventargs E)
{
If (textchanged! = NULL)
{
Textchanged (this, e );
}
}
}
Usage on the page:
<Supercontrol: suppercontrol id = "mycontrol" runat = "server" ontextchanged = "mycontrol_ontextchanged"/>