Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why is this happening??
Message
From
29/01/2009 14:39:41
 
 
To
29/01/2009 14:00:35
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
General information
Forum:
ASP.NET
Category:
Forms
Miscellaneous
Thread ID:
01378204
Message ID:
01378244
Views:
13
Sorry if I didn't do a good job of explaining. The control is defined separately in a Libarary. Then I've dropped the control onto a Panel, which is on the Form mainwin ...hopefully that will make my problem more clear.

bob


>Bob,
>
>>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
>
>Just to make sure I understand this right. You have a control that you have placed on a form. You have code in the control that based on some action in the control needs to run some code within the form. If so, the idea with controls being self contained is they should not really know anything about the form using them. Another way you could do this is to define an event in the control and raise that event based on some action. The form can subscribe to that event and when it is raised it would respond by running that code.
>Tim
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform