473,775 Members | 2,529 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Event Handlers

Where is the best place to define event handlers? I need to define event
handlers for a COM object referenced in my project and am doing so in the
fowm load. Is this the best place?

Dec 20 '06 #1
6 2122
Hello Jake,

In asp.net the general place for event handlers is Page_Init, but it's common
for the page controls
In your case you can put defining there.

I don't think that the Page_Load is really the best case, because you need
to check whether it's postbacked or not

JKWhere is the best place to define event handlers? I need to define
JKevent handlers for a COM object referenced in my project and am
JKdoing so in the fowm load. Is this the best place?
JK>
---
WBR,
Michael Nemtseva [C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
Dec 21 '06 #2
Thanks for the reply.

I forgot to mention that I am building a Windows Forms project that will
eventually become a service. Where would the best place be in this case to
define event handlers?

"Michael Nemtsev" <ne*****@msn.co mwrote in message
news:a2******** *************** ****@msnews.mic rosoft.com...
Hello Jake,

In asp.net the general place for event handlers is Page_Init, but it's
common for the page controls
In your case you can put defining there.

I don't think that the Page_Load is really the best case, because you need
to check whether it's postbacked or not

JKWhere is the best place to define event handlers? I need to define
JKevent handlers for a COM object referenced in my project and am
JKdoing so in the fowm load. Is this the best place?
JK---
WBR,
Michael Nemtseva [C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

Dec 21 '06 #3
Hi Jake,

There is no best place. It depends on the scope and lifetime of the object.
If the object is created by a class when the class is created, and if the
object will remain useable for as long as the class that contains it, then
registering event handlers in the class's constructor is usually suitable.
If the object will be useable after the class that contains it has been
disposed then be sure to unregister the event handlers in the class's
dispose method.

If the object is created in some method rather than the class's constructor
then register the event handlers when the object is created in the method.

--
Dave Sexton

"Jake K" <no*****@addres s.comkwrote in message
news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
Where is the best place to define event handlers? I need to define event
handlers for a COM object referenced in my project and am doing so in the
fowm load. Is this the best place?

Dec 21 '06 #4
Thanks. The object will only be usable in a single class. I will register
event handlers in the class' constructor. Thanks.

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
Hi Jake,

There is no best place. It depends on the scope and lifetime of the
object. If the object is created by a class when the class is created, and
if the object will remain useable for as long as the class that contains
it, then registering event handlers in the class's constructor is usually
suitable. If the object will be useable after the class that contains it
has been disposed then be sure to unregister the event handlers in the
class's dispose method.

If the object is created in some method rather than the class's
constructor then register the event handlers when the object is created in
the method.

--
Dave Sexton

"Jake K" <no*****@addres s.comkwrote in message
news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
>Where is the best place to define event handlers? I need to define event
handlers for a COM object referenced in my project and am doing so in the
fowm load. Is this the best place?

Dec 21 '06 #5
Does it matter where InitializeCompo nent(); appears in the default
constructor? E.g. Is this correct or does InitializeCompo nent need to be
the first line?

namespace whatever
{

public partial class Form1 : Form
{
//fields defined here, etc.
}

public Form1 //default constructor
{
COMObject1 = new COMObjectClass( );
COMObject1.Meth odName += new
COMObjectLib._I COMObjectEvents _MethosNameEven tHandler(OnCOMO bject1MethodNam e);
InitializeCompo nent();
}

private void OnCOMObject1Met hodName()
{
}

}


"Jake K" <no*****@addres s.comkwrote in message
news:u3******** ******@TK2MSFTN GP04.phx.gbl...
Thanks. The object will only be usable in a single class. I will
register event handlers in the class' constructor. Thanks.

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
>Hi Jake,

There is no best place. It depends on the scope and lifetime of the
object. If the object is created by a class when the class is created,
and if the object will remain useable for as long as the class that
contains it, then registering event handlers in the class's constructor
is usually suitable. If the object will be useable after the class that
contains it has been disposed then be sure to unregister the event
handlers in the class's dispose method.

If the object is created in some method rather than the class's
constructor then register the event handlers when the object is created
in the method.

--
Dave Sexton

"Jake K" <no*****@addres s.comkwrote in message
news:%2******* *********@TK2MS FTNGP06.phx.gbl ...
>>Where is the best place to define event handlers? I need to define
event handlers for a COM object referenced in my project and am doing so
in the fowm load. Is this the best place?

Dec 21 '06 #6
Hi Jake,

In your situation it doesn't matter since COMObjectClass isn't instantiated
and configured by the designer, but you should make it a habit of putting
InitializeCompo nent as the first line anyway since it's not uncommon to
manipulate designer-serialized controls in the constructor.

--
Dave Sexton

"Jake K" <no*****@addres s.comkwrote in message
news:u3******** ******@TK2MSFTN GP03.phx.gbl...
Does it matter where InitializeCompo nent(); appears in the default
constructor? E.g. Is this correct or does InitializeCompo nent need to be
the first line?

namespace whatever
{

public partial class Form1 : Form
{
//fields defined here, etc.
}

public Form1 //default constructor
{
COMObject1 = new COMObjectClass( );
COMObject1.Meth odName += new
COMObjectLib._I COMObjectEvents _MethosNameEven tHandler(OnCOMO bject1MethodNam e);
InitializeCompo nent();
}

private void OnCOMObject1Met hodName()
{
}

}


"Jake K" <no*****@addres s.comkwrote in message
news:u3******** ******@TK2MSFTN GP04.phx.gbl...
>Thanks. The object will only be usable in a single class. I will
register event handlers in the class' constructor. Thanks.

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:%2******* *********@TK2MS FTNGP06.phx.gbl ...
>>Hi Jake,

There is no best place. It depends on the scope and lifetime of the
object. If the object is created by a class when the class is created,
and if the object will remain useable for as long as the class that
contains it, then registering event handlers in the class's constructor
is usually suitable. If the object will be useable after the class that
contains it has been disposed then be sure to unregister the event
handlers in the class's dispose method.

If the object is created in some method rather than the class's
constructor then register the event handlers when the object is created
in the method.

--
Dave Sexton

"Jake K" <no*****@addres s.comkwrote in message
news:%2****** **********@TK2M SFTNGP06.phx.gb l...
Where is the best place to define event handlers? I need to define
event handlers for a COM object referenced in my project and am doing
so in the fowm load. Is this the best place?

Dec 21 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
3605
by: tony kulik | last post by:
This code works fine in ie and opera but not at all in Mozilla. Anybody got a clue as to how to get it right? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <script language="JavaScript" type="text/javascript"> function show(that) { if (box.style.visibility=='hidden') { that.style.visibility = 'visible'}; }
8
3128
by: Dennis C. Drumm | last post by:
I have a class derived from a SortedList called SystemList that contains a list of objects indexed with a string value. The definition of the objects contained in the SortedList have a boolean field and an event that is fired if the boolean field value changes. The derived SortedList class has an override for the Add method. The Add method adds an event handler for the object's event for each new item added to the list. In the...
18
4851
by: bhavin | last post by:
Hi, Can someone point me to some good best practices kind of documentation on use of events compared to method overriding. Ex. In Windows Forms when should i have an event handler for Paint, and when should i override OnPaint? I have to implement added functionality in a child class, and am in two minds .. to have the parent fire an event, or make the method virtual and override in the child. Am hoping some reading with description of...
13
3518
by: Charles Law | last post by:
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my question about removing event handlers. > http://www.vbinfozine.com/t_bindevt.shtml Following on from that post, the following issues still exist. The article shows how to find methods on a receiver that match the pattern OnXXXX given the sender. It loops through the sender events and tries to get methods from the receiver that match the pattern. For each one...
5
3882
by: Amit | last post by:
Hello! Is it possible to find how many event handlers an event has at runtime? How about finding whether or not an event has event handlers? In C# you can compare the event with null to check if it has event handlers, but I can't find the equivalent in VB. Thanks Amit
6
28169
by: Kevin Attard | last post by:
I am using a GridView inside a UserControl which has a template column for deleting the rows. Before databinding the gridview i am attaching the RowCommand and RowDataBound event. I am using the RowDataBound event to set the commandargument of the delete button. The event is being fired and works fine. When I press the delete button, the RowCommand event is not firing! and neither is the RowDeleting (the button's commandName is...
16
2517
by: Hamed | last post by:
Hello I am developing a utility to be reused in other programs. It I have an object of type Control (a TextBox, ComboBox, etc.) that other programmers use it in applications. they may set some of properties or assign event handlers. I need to be able to clone the manipulated control at runtime. I could use the Clone method of some objects (like Font, Style, String,
14
8640
by: Hamed | last post by:
Hello It seems that I should implement ICloneable to implement my own clone object. the critical point for me is to make a control object based on another control object that all of its event handlers are set like the old one. Is there a way to do this job? For example, is there a way to use EventInfo object to get all event handlers of the old control in runtime and set my new cloned control events to the event handlers of the old...
6
2021
by: Tony Johansson | last post by:
Hello! I know it's possible to have several event handler for a single event but I can't see any point using several event handler for this. I'm probably wrong so can anybody tell me what advantage it might give using several event handler for a single event.
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10270
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10051
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8939
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7464
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6718
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4017
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2853
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.