Snippet
namespace ActiveTest { public partial class WebUserControl : UserControl { public delegate void SayHelloHandler(Label label); public event SayHelloHandler SayHello; Label label = new Label(); protected override void OnInit(EventArgs e) { base.OnInit(e); this.Controls.Add(label); } protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (this.SayHello != null) this.SayHello(label); else label.Text = "<h2>Hello from base class</h2>"; } } }Page
Snippet
<%@ Register Src="~/WebUserControl.ascx" TagName="WebUserControl" TagPrefix="asp" %> <%@ Page Language="C#" %> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <script runat="server"> protected void SayHello(Label label) { label.Text = "<h1>Hello from consuming page</h1>"; } </script> </head> <body> <form id="form2" runat="server"> <asp:WebUserControl ID="WebUserControl1" runat="server" /> <asp:WebUserControl ID="WebUserControl2" OnSayHello="SayHello" runat="server" /> </form> </body> </html>
No comments:
Post a Comment