Wednesday, April 16, 2008

raise events from a user control

Did you know you can raise events from a user control? Here's a little sample, LabelButton.ascx (essentially the equivalent of asp:LinkButton), that demonstrates implementing a postback event like click. Controls that fires postback events must implement the IPostBackEventHandler interface -- see the first directive of the user control. Cool, huh? LabelButton.ascx <%@ Implements Interface="System.Web.UI.IPostBackEventHandler" %> > ' runat="server"/> And here's a consuming page TestPage.aspx: <%@ Register TagPrefix="ev" TagName="LabelButton" Src="LabelButton.ascx"%>

No comments: