Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Why is this happening??
Message
De
29/01/2009 13:43:57
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Titre:
Why is this happening??
Divers
Thread ID:
01378204
Message ID:
01378204
Vues:
72
I have some code in a custom contol that is trying to run code in the form that the control is placed on. I want the code to be written in the control so I don't have to duplicate it for each contol I place on the form (I hear that's good programming practice :).

Here's the code:

MainWin1 = (MainWindow)this.TopLevelControl;
MainWin1.MainMenu(MainWindow.MenuName.search);

The code works great the first time the contol is clicked, but the second time its clicked it gives a NULL exception as the this.TopLevelControl is null for some reason.

So I traced it and for some reason the second time through it ran the click event twice (that executes the above code) so I thought if I just ignored the time that this.TopLevelControl was null I'd be OK. But then I get a NULL exception for the mainwin variable at the very top of my program that invokes the main window in the first place:

MainWindow mainwin = new MainWindow();
Application.Run(mainwin); - This turns NULL for some reason.

Any Ideas anyone? I don't have a clue why this would be happening. The main form hasn't been closed in the interim between the two clicks. OR Am I approaching this wrong and should I try a different approach to executing code in the mainform from a custom control?

Thanks!!

bob
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform