Chapter 4. User Controls: From Page to Control


Chapter 4. User Controls: From Page to Control

In this chapter, we will describe the user control model, show how to author a user control, and discuss the features of user controls. In Chapter 5, "Developing a Simple Custom Control," we will introduce the custom control model, and in Chapter 6, "Custom Controls vs. User Controls," we'll compare the two models to help you decide which one to use when developing your own ASP.NET server controls.

A user control is a server control that you author in the same WYSIWYG and declarative style as an ASP.NET page and save as a text file with an .ascx extension. You do not have to precompile a user control. When a user control is used in an .aspx page, the page parser dynamically generates a class from the .ascx file and compiles it into an assembly (managed library). This combination of page-style authoring and no-compile deployment makes it easy to develop a user control.

User controls enable you to save common user interface (UI) portions of a page ”such as headers, footers, and navigation bars ”and to reuse them across an application. User controls also enable you to partition pages into smaller units, which simplifies the task of developing and maintaining pages.

User controls are a significantly better solution for UI reuse than server-side includes , the main reuse mechanism available in traditional Active Server Pages programming. A server-side include merely inserts inline text from an included file and is similar to file concatenation. A user control, on the other hand, is a class with its own object model that a page developer can program against. A user control has an added benefit: its programming language can differ from that of the containing page. This means user controls written in different programming languages can be used on a single page. A server-side include, on the other hand, must be written in the same language as the including page. (The user control model in Microsoft Visual Studio .NET is slightly different. A user control in Visual Studio .NET must be developed in the same language as its containing page and project.)



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