Custom Event Handling within UserControl

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nicole - ASP/C# Beginner

    Custom Event Handling within UserControl

    I am trying to kick off an custom event in a usercontrol that the webpage
    will listen and preform some actions if the event is fired from within my
    usercontrol
  • Alex Korchemniy

    #2
    RE: Custom Event Handling within UserControl

    First you need to create a delegate. Do this outside the class:

    public delegate void MyCustomEventHa ndler(object sender, MyCustomEventAr gs e);

    The above is an example of a delegate that you can define.

    In side the class you then do the following:

    public class MyClass
    {
    public event MyCustomEventHa ndler MyEvent;
    .....
    }

    To fire the event you can do this:

    if (MyEvent != null)
    MyEvent(sender, args);

    ----
    Alex Korchemniy

    "Nicole - ASP/C# Beginner" wrote:
    [color=blue]
    > I am trying to kick off an custom event in a usercontrol that the webpage
    > will listen and preform some actions if the event is fired from within my
    > usercontrol[/color]

    Comment

    • Nicole - ASP/C# Beginner

      #3
      RE: Custom Event Handling within UserControl

      What would MyCustomEventAr gs represent. Can I define it as something.

      "Alex Korchemniy" wrote:
      [color=blue]
      > First you need to create a delegate. Do this outside the class:
      >
      > public delegate void MyCustomEventHa ndler(object sender, MyCustomEventAr gs e);
      >
      > The above is an example of a delegate that you can define.
      >
      > In side the class you then do the following:
      >
      > public class MyClass
      > {
      > public event MyCustomEventHa ndler MyEvent;
      > ....
      > }
      >
      > To fire the event you can do this:
      >
      > if (MyEvent != null)
      > MyEvent(sender, args);
      >
      > ----
      > Alex Korchemniy
      >
      > "Nicole - ASP/C# Beginner" wrote:
      >[color=green]
      > > I am trying to kick off an custom event in a usercontrol that the webpage
      > > will listen and preform some actions if the event is fired from within my
      > > usercontrol[/color][/color]

      Comment

      Working...