Exposing an EventHandler as a property in a UserControl

Last post 06-27-2008 3:36 PM by joteke. 1 replies.

Sort Posts:

  • Exposing an EventHandler as a property in a UserControl

    06-27-2008, 11:05 AM
    • Member
      2 point Member
    • mkubaryc
    • Member since 06-23-2008, 5:58 PM
    • Posts 30

     I know it has been asked before but I can't seem to find an answer.

     I have a User Control that I want to expose an eventhandler as a property.  For example, I want to be able to specify the event handler in markup (<Control Event="control_event">) or by doing it in code behind (ie: UserControl.attributes.add("Event", "control_event")).

     Now that I look at what I want a little further...is this even possible?

  • Re: Exposing an EventHandler as a property in a UserControl

    06-27-2008, 3:36 PM
    Answer
    • All-Star
      46,032 point All-Star
    • joteke
    • Member since 06-16-2002, 3:24 PM
    • Kyro, Finland
    • Posts 6,879
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    Hi,

    for the UserControl.attributes.add("Event", "control_event"))  see my blog post:

    Mapping of attributes to control properties in ASP.NET - growing to a custom control
    http://aspadvice.com/blogs/joteke/archive/2007/08/16/Mapping-of-attributes-to-control-properties-in-ASP.NET.aspx

    The mechanism itself works  equally for user control as well as custom controls. You can declare an event which ther control raises in specific circumstances and other controls can listen to that event, and then do what they need to do based on it.

    Thanks,

    Teemu Keiski
    Finland, EU
Page 1 of 1 (2 items)