By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,278 Members | 1,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,278 IT Pros & Developers. It's quick & easy.

User Control Events....

P: n/a
Hi all,
i do have a user control with 4 buttons, and all the events
are firing properly,

My problem is that i need to right an event handler in the user
control, which gets fired after a specific process is done,, but the
form which will host the user control has to specify what has to be
done

Something like this , if the event is fired it should call the event in
the page which is hosted

Help me out

Thanks in Advance

thomson

Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Create a public event on the usercontrol that can be wired up to from the
page. So in your click event in the usercontrol you raise the event.
Nov 19 '05 #2

P: n/a
Hi thomson,

Actually, you don't want to write an event handler in the User Control. You
want to raise an event in the User Control, which can be handled by an event
handler in the form hosting it, if I understand you correctly. To make sure
that I DO understand you correctly, let me restate your problem, and let me
know if my interpretation is correct.

You have a User Control, which is similar to a Page in that it is a Control
that hosts other Controls. You mention that these hosted Controls, 4
buttons, fire events which are handled by the User Control hosting them. So
far, so good. Right? Okay, now don't forget that I mentioned that the Page
which hosts the User Control is similar in this respect to the User Control
itself, in that any Control can host other Controls that raise events, and
subscribe to the events with event handler methods.

So, what you want to do is to have the User Control, like a Button Control,
RAISE an event when it finishes a process of some kind, that the Page which
hosts that Control can respond to with its own event HANDLER method.

Did I get the problem right? I think it would help for you to fully
understand the following terms:

EventArgs - A class from which EventArgs classes are derived via
inheritance. EventArgs classes may or may not contain data (information)
about the class which raised the Event, or about the process in which the
Event was raised.

Delegate - A "template" for an Event Handler method, specifically for a
certain EventArgs type (class). A Delegate is similar to a "stubbed-out"
method, that is, a method that contains no process, but only a signature
(return type, name and parameters).

Raising an Event - a process that creates an EventArgs class, or a class
that inherits EventArgs, and broadcasts it to any subscribers to the Event.
Note that the broadcast itself is synchronous, that is, happening in a
sequence of instructions (process), but that the Event Handler method is
asynchronous, that is, happening in a separate thread from the current
execution thread in the class that responds to the Event.

Event Handler - a special method that has a signature matching a delegate
method for a specific type of EventArgs class. The Event Handler operates
asynchronously (in a spearate thread) from the current process being
executed by that class (the class that subscribes to the Event).

Subscribing to an Event - a process which "wires up" an EventHandler method
to an Event which may or may not be raised by another class.

Now, as to how to write the code, well, it differs in C# and VB.Net
(surprise, surprise). So, if you can tell me which language you're using, I
can give you some examples. If you're using VB.Net, this may account for
some of the confusion, as VB.Net can hide a lot of this, and allows you to
write simpler-LOOKING code to raise and handle events. Under the hood, of
course, both languages are doing the same thing, but it is actually easier
to see what is going on in C#, which is more strict about the code you
write.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.
"thomson" <sa**********@yahoo.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Hi all,
i do have a user control with 4 buttons, and all the events
are firing properly,

My problem is that i need to right an event handler in the user
control, which gets fired after a specific process is done,, but the
form which will host the user control has to specify what has to be
done

Something like this , if the event is fired it should call the event in
the page which is hosted

Help me out

Thanks in Advance

thomson

Nov 19 '05 #3

P: n/a
UJ
Kevin,
I'm not the original poster but I'd be interested in how to do this in
VB.Net. I would like to do the same type of thing.

TIA - Jeffrey.

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:uc**************@TK2MSFTNGP15.phx.gbl...
Hi thomson,

Actually, you don't want to write an event handler in the User Control.
You want to raise an event in the User Control, which can be handled by an
event handler in the form hosting it, if I understand you correctly. To
make sure that I DO understand you correctly, let me restate your problem,
and let me know if my interpretation is correct.

You have a User Control, which is similar to a Page in that it is a
Control that hosts other Controls. You mention that these hosted Controls,
4 buttons, fire events which are handled by the User Control hosting them.
So far, so good. Right? Okay, now don't forget that I mentioned that the
Page which hosts the User Control is similar in this respect to the User
Control itself, in that any Control can host other Controls that raise
events, and subscribe to the events with event handler methods.

So, what you want to do is to have the User Control, like a Button
Control, RAISE an event when it finishes a process of some kind, that the
Page which hosts that Control can respond to with its own event HANDLER
method.

Did I get the problem right? I think it would help for you to fully
understand the following terms:

EventArgs - A class from which EventArgs classes are derived via
inheritance. EventArgs classes may or may not contain data (information)
about the class which raised the Event, or about the process in which the
Event was raised.

Delegate - A "template" for an Event Handler method, specifically for a
certain EventArgs type (class). A Delegate is similar to a "stubbed-out"
method, that is, a method that contains no process, but only a signature
(return type, name and parameters).

Raising an Event - a process that creates an EventArgs class, or a class
that inherits EventArgs, and broadcasts it to any subscribers to the
Event. Note that the broadcast itself is synchronous, that is, happening
in a sequence of instructions (process), but that the Event Handler method
is asynchronous, that is, happening in a separate thread from the current
execution thread in the class that responds to the Event.

Event Handler - a special method that has a signature matching a delegate
method for a specific type of EventArgs class. The Event Handler operates
asynchronously (in a spearate thread) from the current process being
executed by that class (the class that subscribes to the Event).

Subscribing to an Event - a process which "wires up" an EventHandler
method to an Event which may or may not be raised by another class.

Now, as to how to write the code, well, it differs in C# and VB.Net
(surprise, surprise). So, if you can tell me which language you're using,
I can give you some examples. If you're using VB.Net, this may account for
some of the confusion, as VB.Net can hide a lot of this, and allows you to
write simpler-LOOKING code to raise and handle events. Under the hood, of
course, both languages are doing the same thing, but it is actually easier
to see what is going on in C#, which is more strict about the code you
write.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Ambiguity has a certain quality to it.
"thomson" <sa**********@yahoo.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Hi all,
i do have a user control with 4 buttons, and all the events
are firing properly,

My problem is that i need to right an event handler in the user
control, which gets fired after a specific process is done,, but the
form which will host the user control has to specify what has to be
done

Something like this , if the event is fired it should call the event in
the page which is hosted

Help me out

Thanks in Advance

thomson


Nov 19 '05 #4

P: n/a
Hi Jeffrey,

Sorry to get back to you so late - serious deadline on top of me!

As I DO have a serious deadline, I hope you'll forgive me if I point you to
an excellent section of the online MSDN Library, which has a number of
articles and tutorials dealing with raising and consuming events in
VisualBasic.Net:

http://msdn.microsoft.com/library/de...singEvents.asp

Also, if anyone wants to read about this for C#:

http://msdn.microsoft.com/library/de...tsTutorial.asp

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"UJ" <fr**@nowhere.com> wrote in message
news:Ol**************@TK2MSFTNGP14.phx.gbl...
Kevin,
I'm not the original poster but I'd be interested in how to do this in
VB.Net. I would like to do the same type of thing.

TIA - Jeffrey.

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:uc**************@TK2MSFTNGP15.phx.gbl...
Hi thomson,

Actually, you don't want to write an event handler in the User Control.
You want to raise an event in the User Control, which can be handled by
an event handler in the form hosting it, if I understand you correctly.
To make sure that I DO understand you correctly, let me restate your
problem, and let me know if my interpretation is correct.

You have a User Control, which is similar to a Page in that it is a
Control that hosts other Controls. You mention that these hosted
Controls, 4 buttons, fire events which are handled by the User Control
hosting them. So far, so good. Right? Okay, now don't forget that I
mentioned that the Page which hosts the User Control is similar in this
respect to the User Control itself, in that any Control can host other
Controls that raise events, and subscribe to the events with event
handler methods.

So, what you want to do is to have the User Control, like a Button
Control, RAISE an event when it finishes a process of some kind, that the
Page which hosts that Control can respond to with its own event HANDLER
method.

Did I get the problem right? I think it would help for you to fully
understand the following terms:

EventArgs - A class from which EventArgs classes are derived via
inheritance. EventArgs classes may or may not contain data (information)
about the class which raised the Event, or about the process in which the
Event was raised.

Delegate - A "template" for an Event Handler method, specifically for a
certain EventArgs type (class). A Delegate is similar to a "stubbed-out"
method, that is, a method that contains no process, but only a signature
(return type, name and parameters).

Raising an Event - a process that creates an EventArgs class, or a class
that inherits EventArgs, and broadcasts it to any subscribers to the
Event. Note that the broadcast itself is synchronous, that is, happening
in a sequence of instructions (process), but that the Event Handler
method is asynchronous, that is, happening in a separate thread from the
current execution thread in the class that responds to the Event.

Event Handler - a special method that has a signature matching a delegate
method for a specific type of EventArgs class. The Event Handler operates
asynchronously (in a spearate thread) from the current process being
executed by that class (the class that subscribes to the Event).

Subscribing to an Event - a process which "wires up" an EventHandler
method to an Event which may or may not be raised by another class.

Now, as to how to write the code, well, it differs in C# and VB.Net
(surprise, surprise). So, if you can tell me which language you're using,
I can give you some examples. If you're using VB.Net, this may account
for some of the confusion, as VB.Net can hide a lot of this, and allows
you to write simpler-LOOKING code to raise and handle events. Under the
hood, of course, both languages are doing the same thing, but it is
actually easier to see what is going on in C#, which is more strict about
the code you write.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Ambiguity has a certain quality to it.
"thomson" <sa**********@yahoo.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Hi all,
i do have a user control with 4 buttons, and all the events
are firing properly,

My problem is that i need to right an event handler in the user
control, which gets fired after a specific process is done,, but the
form which will host the user control has to specify what has to be
done

Something like this , if the event is fired it should call the event in
the page which is hosted

Help me out

Thanks in Advance

thomson



Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.