Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem when created OnLoad Method
Message
De
23/01/2010 11:21:33
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01445631
Message ID:
01445639
Vues:
23
>>>>>Hi,
>>>>>
>>>>>I wanted to add OnLoad method to my form class. Here is what I did:
>>>>>
>>>>>1. In the Win Form Property window I selected Events and then clicked on Load event.
>>>>>
>>>>>This created a method in the form class as following:
>>>>>
>>>>>
>>>>>       private void frmMyFormName_Load(object sender, EventArgs e)
>>>>>        {
>>>>>        }
>>>>>
>>>>>
>>>>>2. Then I added a line base.OnLoad(e) as following:
>>>>>
>>>>>
>>>>>       private void frmMyFormName_Load(object sender, EventArgs e)
>>>>>        {
>>>>>            base.OnLoad(e);
>>>>>        }
>>>>>
>>>>>
>>>>>Now when I run the form I get error "System.StackOverflowException". What am I missing?
>>>>>
>>>>>TIA
>>>>
>>>>Don't call the OnLoad()! It's OnLoad() method that fires the Load event which you are handling (which calls the OnLoad() which fires the Load which calls the OnLoad which .... but you get the picture)
>>>
>>>Viv,
>>>
>>>I think I see now. I was following your message from several days ago where you indicated where to place the LoadData() method. And I completely misunderstood your message. You wrote to place it as following:
>>>
>>>protected override void OnLoad(EventArgs e)
>>>{ 
>>>     LoadData();
>>>     base.OnLoad(e);
>>>}
>>>
>>>
>>>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.....
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform