E
Eddy POULLET
hi,
I have a control with an event handler
this.Button.Click += new System.EventHandler(this.FormData_Changed);
Apparently the code below is not compilable
if ( this.Button.Click != null) // CS0079
{
....
}
Question : How can I known if a (or how much) handler exists for an
event ?
To avoid recursion, I do
this.Button.Click -= new System.EventHandler(this.FormData_Changed);
....
this.Button.Click += new System.EventHandler(this.FormData_Changed);
But I would write to have a cleaner code :
bExist = false;
if (this.Button.Click != null)
{
this.Button.Click -= new System.EventHandler(this.FormData_Changed);
bExist = true;
}
....
....
if (bExist)
this.Button.Click += new System.EventHandler(this.FormData_Changed);
Thanks a lot,
Eddy POULLET
Brussels
I have a control with an event handler
this.Button.Click += new System.EventHandler(this.FormData_Changed);
Apparently the code below is not compilable
if ( this.Button.Click != null) // CS0079
{
....
}
Question : How can I known if a (or how much) handler exists for an
event ?
To avoid recursion, I do
this.Button.Click -= new System.EventHandler(this.FormData_Changed);
....
this.Button.Click += new System.EventHandler(this.FormData_Changed);
But I would write to have a cleaner code :
bExist = false;
if (this.Button.Click != null)
{
this.Button.Click -= new System.EventHandler(this.FormData_Changed);
bExist = true;
}
....
....
if (bExist)
this.Button.Click += new System.EventHandler(this.FormData_Changed);
Thanks a lot,
Eddy POULLET
Brussels