Content and Layout


Custom controls and user controls offer different capabilities for content and layout because of their differing authoring mechanisms. A control's content includes any static text as well as any child controls it contains or renders within itself. A control's layout provides the structure within which its content is rendered.

Custom controls are very well suited to dynamic content presented in a programmatically generated layout. For example, scenarios such as a data-bound table control with dynamic rows, a tree control with dynamic nodes, or a tab control with dynamic tabs are best implemented as custom controls. In these scenarios, the content and layout are typically dependent on property values and logical conditions based on those values. Custom controls are usually designed for reuse across applications and almost never have any static hard-coded text. Instead, any textual content in their rendering is customizable via string properties.

Because the layout of a user control is declared at authoring time within the .ascx file, user controls are a much better choice when you want relatively static content with a fixed layout. A perfect example of user controls with relatively static content are user controls utilized as headers and footers in pages within a site or application (such as the SiteHeader and SiteFooter user controls used in the sample pages within the BookWeb application) to implement a consistent and easily modifiable look. A user control can offer a small degree of customizability through properties such as Text or URL (as the LinkGlyph sample in Chapter 4 demonstrates ). A user control that implements dynamic layout cannot fully utilize the declarative model and layout capabilities that are available at authoring time, even though these are the essence of the user control model. An application-specific user control is well suited for containing static textual content ”a common scenario when you need to factor out a reusable snippet of application-specific HTML content.



Developing Microsoft ASP. NET Server Controls and Components
Developing Microsoft ASP.NET Server Controls and Components (Pro-Developer)
ISBN: 0735615829
EAN: 2147483647
Year: 2005
Pages: 183

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net