Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Where's the Reference?
Message
From
28/06/2004 21:49:32
 
 
To
28/06/2004 11:00:53
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00917978
Message ID:
00918237
Views:
5
I think I have found what I was missing and ask for any comments regarding my solution.

First I forgot something I learned my first week working with ASP.Net . VS does not automatically add a declaration to code-behind for user controls. See BUG: Visual Studio .NET Does Not Generate a Code-Behind Declaration for Web User Controls http://support.microsoft.com/default.aspx?scid=kb;EN-US;316370.

After adding a declaration for the nested user control, I now have a reference to the user control from code-behind of the container User Control and it appears in intellisence.

Next, how do I call properties and methods of the nested User Control. At first I manually changed the auto-generated declarations in the nested user control from Protected to Public. This worked, and I could reference the controls from the container control’s code-behind, they where available in inellisence. However I know it is a no-no to change auto-generated code so I added public readonly properties that return a reference to the controls I want to manipulate from the container user control. So far this seems to work.

Once I got a reference to the nested user control I could wire up the event. I use a public event, raised in the ItemCommand event handler of a grid in the nested control, to communicate the event to the container control, thus allowing the container control to respond to the grid event of the nested control. (The ItemCommand of the grid is not public) Sounds confusing but it works.

Please let me know if this is the right approach. There may be an easier way and I’m all for learning easy.

Regards,

Terry Carroll




>I have placed a user control “Hats.ascx”” on another user control “Clothing.ascx”.
>
>Questions:
>
>How can I reference the properties and methods of the controls in Hats from the code-behind of Clothing? Hats does not appear in intellisence.
>
>Can the properties and methods of the controls in hats.ascx be set public so they can be changed form other user controls and the host page? The code generator sets all of them to Protected. In winforms this can be changed from the property sheet but, I suspect because web forms does not support visual inheritance, it might not support setting controls public.
>
>I have a public event in hats and want to add a handler for this event in Clothing. If I can get a reference to Hats from within the Clothing code-behind , is it possible to add an event handler across user controls? The event will be raised in Hats.ascx.
>
>I hope I’m only missing something very basic!
>
>Thanks for the Help,
>
>Terry Carroll
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform