User Control events

Discussion in 'ASP .Net' started by =?Utf-8?B?SmltIFJleW5vbGRz?=, Feb 8, 2005.

  1. Hi I am trying to raise a user control event but in the test the event is
    always null so never fires. Why is this please?

    public event EventHandler Click;

    private void butOK_Click(object sender, System.EventArgs e)
    {
    // Call event method.
    OnClick(EventArgs.Empty);
    }

    protected virtual void OnClick(EventArgs e)
    {
    if (Click != null)
    // Raise the event.
    Click(this, e);
    }
     
    =?Utf-8?B?SmltIFJleW5vbGRz?=, Feb 8, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?SmltIFJleW5vbGRz?=

    Ollie Riches Guest

    I guess this is because nothing is consuming the event, you must provide an
    event handler that executes program logic when the event is raised.

    you will need to have something like this in the code that hosts the user
    control

    XXXX.Click += new EventHandler(this.Button_Clicked);

    where 'Button_Clicked' is a method with the signature

    void Button_Clicked(object sender, EventArgs e)
    {
    .....
    }

    HTH

    Ollie Riches

    "Jim Reynolds" <> wrote in message
    news:...
    > Hi I am trying to raise a user control event but in the test the event is
    > always null so never fires. Why is this please?
    >
    > public event EventHandler Click;
    >
    > private void butOK_Click(object sender, System.EventArgs e)
    > {
    > // Call event method.
    > OnClick(EventArgs.Empty);
    > }
    >
    > protected virtual void OnClick(EventArgs e)
    > {
    > if (Click != null)
    > // Raise the event.
    > Click(this, e);
    > }
    >
     
    Ollie Riches, Feb 8, 2005
    #2
    1. Advertising

  3. Hi Ollie,

    I do have an event handler:

    this.butOK.Click += new System.EventHandler(this.butOK_Click);

    and this fires ok. It's when it gets to the onClick method that the Click
    event is always null so never fires the Click event.

    "Ollie Riches" wrote:

    > I guess this is because nothing is consuming the event, you must provide an
    > event handler that executes program logic when the event is raised.
    >
    > you will need to have something like this in the code that hosts the user
    > control
    >
    > XXXX.Click += new EventHandler(this.Button_Clicked);
    >
    > where 'Button_Clicked' is a method with the signature
    >
    > void Button_Clicked(object sender, EventArgs e)
    > {
    > .....
    > }
    >
    > HTH
    >
    > Ollie Riches
    >
    > "Jim Reynolds" <> wrote in message
    > news:...
    > > Hi I am trying to raise a user control event but in the test the event is
    > > always null so never fires. Why is this please?
    > >
    > > public event EventHandler Click;
    > >
    > > private void butOK_Click(object sender, System.EventArgs e)
    > > {
    > > // Call event method.
    > > OnClick(EventArgs.Empty);
    > > }
    > >
    > > protected virtual void OnClick(EventArgs e)
    > > {
    > > if (Click != null)
    > > // Raise the event.
    > > Click(this, e);
    > > }
    > >

    >
    >
    >
     
    =?Utf-8?B?SmltIFJleW5vbGRz?=, Feb 8, 2005
    #3
  4. =?Utf-8?B?SmltIFJleW5vbGRz?=

    Ollie Riches Guest

    where is the event handler code ?


    "Jim Reynolds" <> wrote in message
    news:...
    > Hi Ollie,
    >
    > I do have an event handler:
    >
    > this.butOK.Click += new System.EventHandler(this.butOK_Click);
    >
    > and this fires ok. It's when it gets to the onClick method that the Click
    > event is always null so never fires the Click event.
    >
    > "Ollie Riches" wrote:
    >
    > > I guess this is because nothing is consuming the event, you must provide

    an
    > > event handler that executes program logic when the event is raised.
    > >
    > > you will need to have something like this in the code that hosts the

    user
    > > control
    > >
    > > XXXX.Click += new EventHandler(this.Button_Clicked);
    > >
    > > where 'Button_Clicked' is a method with the signature
    > >
    > > void Button_Clicked(object sender, EventArgs e)
    > > {
    > > .....
    > > }
    > >
    > > HTH
    > >
    > > Ollie Riches
    > >
    > > "Jim Reynolds" <> wrote in message
    > > news:...
    > > > Hi I am trying to raise a user control event but in the test the event

    is
    > > > always null so never fires. Why is this please?
    > > >
    > > > public event EventHandler Click;
    > > >
    > > > private void butOK_Click(object sender, System.EventArgs e)
    > > > {
    > > > // Call event method.
    > > > OnClick(EventArgs.Empty);
    > > > }
    > > >
    > > > protected virtual void OnClick(EventArgs e)
    > > > {
    > > > if (Click != null)
    > > > // Raise the event.
    > > > Click(this, e);
    > > > }
    > > >

    > >
    > >
    > >
     
    Ollie Riches, Feb 8, 2005
    #4
  5. inside

    InitializeComponent()

    Jim

    "Ollie Riches" wrote:

    > where is the event handler code ?
    >
    >
    > "Jim Reynolds" <> wrote in message
    > news:...
    > > Hi Ollie,
    > >
    > > I do have an event handler:
    > >
    > > this.butOK.Click += new System.EventHandler(this.butOK_Click);
    > >
    > > and this fires ok. It's when it gets to the onClick method that the Click
    > > event is always null so never fires the Click event.
    > >
    > > "Ollie Riches" wrote:
    > >
    > > > I guess this is because nothing is consuming the event, you must provide

    > an
    > > > event handler that executes program logic when the event is raised.
    > > >
    > > > you will need to have something like this in the code that hosts the

    > user
    > > > control
    > > >
    > > > XXXX.Click += new EventHandler(this.Button_Clicked);
    > > >
    > > > where 'Button_Clicked' is a method with the signature
    > > >
    > > > void Button_Clicked(object sender, EventArgs e)
    > > > {
    > > > .....
    > > > }
    > > >
    > > > HTH
    > > >
    > > > Ollie Riches
    > > >
    > > > "Jim Reynolds" <> wrote in message
    > > > news:...
    > > > > Hi I am trying to raise a user control event but in the test the event

    > is
    > > > > always null so never fires. Why is this please?
    > > > >
    > > > > public event EventHandler Click;
    > > > >
    > > > > private void butOK_Click(object sender, System.EventArgs e)
    > > > > {
    > > > > // Call event method.
    > > > > OnClick(EventArgs.Empty);
    > > > > }
    > > > >
    > > > > protected virtual void OnClick(EventArgs e)
    > > > > {
    > > > > if (Click != null)
    > > > > // Raise the event.
    > > > > Click(this, e);
    > > > > }
    > > > >
    > > >
    > > >
    > > >

    >
    >
    >
     
    =?Utf-8?B?SmltIFJleW5vbGRz?=, Feb 8, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sunkam Santhoshi

    Events for menu user control using ie web control

    Sunkam Santhoshi, Dec 16, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    409
    Sunkam Santhoshi
    Dec 16, 2003
  2. Mad Scientist Jr
    Replies:
    0
    Views:
    644
    Mad Scientist Jr
    Mar 22, 2006
  3. Jonathan Wood

    User Control to Control Other User Control

    Jonathan Wood, Jan 24, 2010, in forum: ASP .Net
    Replies:
    4
    Views:
    556
    Jonathan Wood
    Feb 2, 2010
  4. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    373
    Chris
    Aug 30, 2005
  5. Replies:
    1
    Views:
    158
    Peter Michaux
    Apr 27, 2007
Loading...

Share This Page