Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem when created OnLoad Method
Message
From
23/01/2010 12:01:17
 
General information
Forum:
ASP.NET
Category:
Forms
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01445631
Message ID:
01445644
Views:
19
>>>>>>>
>>>>>>>Now I see that what you meant was to create this method (above) in code in the form class and have it call the OnLoad(), right?
>>>>>>
>>>>>>Yep (I updated my message to suggest this but I guess you'd already read it) WIthin the form itself it's probably better to override the OnLoad() method in this way rather then to hook up the Load event which is what you are doing via the property sheet - if you use this approach and look in the Form.Designer.cs file you will see it has generated the hook :
this.Load += new System.EventHandler(this.Form1_Load);
>>>>>
>>>>>Yes, you are right, of course. Now I need to un-hook the method in the .Designer.cs. Do I need to delete the code in the class code and then manually delete it from the .Designer.cs as well? or there is a better way in VS 2005?
>>>>
>>>>I think just clearing the value in the property window should get rid of both the hook in the Form.Designer.cs and the handling stub in the Form.cs. If it doesn't just delete them manually.....
>>>
>>>Yes, executing Reset in the property sheet un-hooks the method. And then I manually deleted it from the class code.
>>>Thank you very much!!!
>>
>>Bear in mind the same approach should be used for nearly all events - in pretty much every case there is a matching OnXxxxxx method ( OnActivated(), OnClick(), OnClose() etc.)
>
>Thank you. I didn't know that this is a better approach and I was hooking up the even via property sheet. To be honest, I don't understand why it is better to use the approach you are suggesting. I will think/read about it more.

Some reasons (there are probably others):
(a) More efficient code.
(b) It provides the option of suppressing the actual event (by not calling the base.Onxxxx()),
(c) It provides the option of executing code before any actual handlers for the event are executed.

OTOH I can't think of any downsides.......
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform