all groups > dotnet clr > november 2005 >
You're in the

dotnet clr

group:

EventHandling problem : Java has solution but what about Microsoft???


Re: EventHandling problem : Java has solution but what about Microsoft??? Andrew Robinson
11/29/2005 10:13:50 AM
dotnet clr:
Mahesh ,

I agree with what Herfried and Marina have written with regards to different
controls of different types.

The one place where I do find it useful to use a single event handler for
multiple controls is with Button Controls. Take a look at the Button Command
event. You can pass different CommandName and CommandArgument strings for
each button while using the same Button Command event handler.

This works with traditional Button controls as well as Link Buttons and
Image Buttons.

--

Andrew Robinson
www.binaryocean.com
www.bellinghamdotnet.org


[quoted text, click to view]
Hi,
I have added few of the events in some control, example code is:
btnControl.GotFocus +=new EventHandler(EventHandlingMethod);
btnControl.Click +=new EventHandler(EventHandlingMethod);
lblControl.Click +=new EventHandler(EventHandlingMethod);
private void EventHandlingMethod(object sender, EventArgs e)
{
.......
}
btnControl = Button object, lblControl = Lable object
Now the problem is: I am adding the same event handler method in all events
for btnControl and lblControl too.
now in EventHandlingMethod method, i can find which control is using sender
but now if i want to put some switch cases in the method for Event Name then
I have no any such information in the eventargs or anyother way....
Can someone help/guide me to get the event name?
Is it possible? if yes then how? If no, then any work around?
Thanks in Advance
Regards,
Mahesh Devjibhai Dhola

Re: EventHandling problem : Java has solution but what about Microsoft??? Marina
11/29/2005 11:14:05 AM
If you need to do different things depending on the event, why not have =
different event handlers? You can place common code into a method that =
both event handlers can call.

I understand what you are saying, but it just doesn't seem like a big =
deal. It is very easy to work around, and most of the time it is not =
even an issue because you either need different code in the handler =
anyway, or the events have different signatures, etc.
"Mahesh Devjibhai Dhola [MVP]" <dholamahesh@hotmail.com> wrote in =
message news:uL$KN7P9FHA.2832@TK2MSFTNGP14.phx.gbl...
Hi,
I have added few of the events in some control, example code is:
btnControl.GotFocus +=3Dnew EventHandler(EventHandlingMethod);
btnControl.Click +=3Dnew EventHandler(EventHandlingMethod);
lblControl.Click +=3Dnew EventHandler(EventHandlingMethod);

private void EventHandlingMethod(object sender, EventArgs e)
{
.......
}

btnControl =3D Button object, lblControl =3D Lable object

Now the problem is: I am adding the same event handler method in all =
events for btnControl and lblControl too.

now in EventHandlingMethod method, i can find which control is using =
sender but now if i want to put some switch cases in the method for =
Event Name then I have no any such information in the eventargs or =
anyother way....

Can someone help/guide me to get the event name?

Is it possible? if yes then how? If no, then any work around?

Thanks in Advance

Regards,
Re: EventHandling problem : Java has solution but what about Microsoft??? Herfried K. Wagner [MVP]
11/29/2005 5:11:46 PM
"Mahesh Devjibhai Dhola [MVP]" <dholamahesh@hotmail.com> schrieb:
I have added few of the events in some control, example code is:
btnControl.GotFocus +=new EventHandler(EventHandlingMethod);
btnControl.Click +=new EventHandler(EventHandlingMethod);
lblControl.Click +=new EventHandler(EventHandlingMethod);

private void EventHandlingMethod(object sender, EventArgs e)
{
.......
}

btnControl = Button object, lblControl = Lable object

Now the problem is: I am adding the same event handler method in all events
for btnControl and lblControl too.

now in EventHandlingMethod method, i can find which control is using sender
but now if i want to put some switch cases in the method for Event Name then
I have no any such information in the eventargs or anyother way....
=======

I am curious which sense handling different events of different controls in
the same event handler would make. Instead, add separate event handlers for
all event types, not just delegate types. This means separate handlers for
controls' 'Click' and 'GotFocus' events.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
EventHandling problem : Java has solution but what about Microsoft??? Mahesh Devjibhai Dhola [MVP]
11/29/2005 9:44:44 PM
Hi,
I have added few of the events in some control, example code is:
btnControl.GotFocus +=3Dnew EventHandler(EventHandlingMethod);
btnControl.Click +=3Dnew EventHandler(EventHandlingMethod);
lblControl.Click +=3Dnew EventHandler(EventHandlingMethod);

private void EventHandlingMethod(object sender, EventArgs e)
{
.......
}

btnControl =3D Button object, lblControl =3D Lable object

Now the problem is: I am adding the same event handler method in all =
events for btnControl and lblControl too.

now in EventHandlingMethod method, i can find which control is using =
sender but now if i want to put some switch cases in the method for =
Event Name then I have no any such information in the eventargs or =
anyother way....

Can someone help/guide me to get the event name?

Is it possible? if yes then how? If no, then any work around?

Thanks in Advance

Regards,
Re: EventHandling problem : Java has solution but what about Microsoft??? Mahesh Devjibhai Dhola [MVP]
11/30/2005 12:00:00 AM
Dear,
The Microsoft Event handling framework allows me to do this what you suggest
but some time, its possible to have such requirement so its not the matter
of sense but its my need so if you can suggest me the woraround for my
prolme then it will be helpful to me.

[quoted text, click to view]

Re: EventHandling problem : Java has solution but what about Microsoft??? Mahesh Devjibhai Dhola [MVP]
11/30/2005 12:00:00 AM
Dear,
I am creating my own framework and its not centric to Buttton or some
control only. It will be applicable to all the events of all the controls.
So i need one common place which will be a common event handler method for
all and from that method my framework will work ahead by checking the sender
control and event name and i am doing lot other things at event time and i
will need more info than just sender and eventargs so i need to have such
method and switch case for event names.
For the same type of situation, java allows to have event name but i am
wondering why Microsoft has not such a simple provision in EventArgs??

[quoted text, click to view]

AddThis Social Bookmark Button