User Control events

G

Guest

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);
}
 
O

Ollie Riches

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
 
G

Guest

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.
 
O

Ollie Riches

where is the event handler code ?


Jim Reynolds said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top