User Control Events....

T

thomson

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
 
J

Josh

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

Kevin Spencer

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

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

Kevin Spencer

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/d...us/vbcn7/html/vbconDeclaringRaisingEvents.asp

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

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcwlkEventsTutorial.asp

--
HTH,

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

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top