I can answer some of these.. =) I've run into the same problem (having common aspects of pages that I want them all to share), but I've implemented this by making the common aspects user controls rather than the other way around (so, I have a control for the
Heading, Navigation, etc, and then my individual pages contain these controls at the right places). Most of my events, therefore, end up in the pages (with the unique controls), and my standard user controls usually don't end up with too much in them. User
Controls do have constructors, but if you add them to a page declaratively (in the HTML), you don't really have access to them. It's easy, however, to define public attributes in your user control, which you can then assign values in your HTML. Quick Sample:
Navigation.ascx
<script runat="server">
Public CurrentPage As String
...
</script>
...
MainPage.aspx
...
<form runat="server">
...
User Controls are separate classes from the page they reside in, and it's probably a good idea to treat them as isolated classes for the most part. In some cases, you may create a user control which is really just a set of controls, and in that case
the page ends up more directly interacting with the control. Otherwise, you just set properties and call methods. Hope this helps! Let me know if there's something I've left unclear. You've covered a lot of ground in your question. -Scott
This posting is provided "AS IS" with no warranties, and confers no rights.
Scott Louvau
Participant
1347 Points
267 Posts
Microsoft
Re: All about User Controls
Aug 07, 2003 01:52 AM|LINK