transparent
Programmer
I have the following code that SHOULD throw an event 'Cancel' when the btnCancel_Click method runs. The btnCancel_Click method does run however, when OnCancel is called Cancel is always Null!! therefore the line in bold if(Cancel !=null) doesn't throw the event. What am I doing wrong??
public delegate void EventHandler(object sender,EventArgs e);
public event EventHandler Cancel;
private void btnCancel_Click(object sender,System.EventArgs e)
{
//Throw Cancel Event!
OnCancel(new EventArgs());
}
protected virtual void OnCancel(EventArgs e)
{
if(Cancel != null)
{
Cancel(this,e);
}
}
public delegate void EventHandler(object sender,EventArgs e);
public event EventHandler Cancel;
private void btnCancel_Click(object sender,System.EventArgs e)
{
//Throw Cancel Event!
OnCancel(new EventArgs());
}
protected virtual void OnCancel(EventArgs e)
{
if(Cancel != null)
{
Cancel(this,e);
}
}