Chapter 7: User Controls

Chapter 7

User Controls

Web forms bring component-based programming to the Internet by enabling complex rendering and behavioral logic to be encoded in reusable server control classes. Classes such as Calendar and DataGrid form the backbone of Web forms and enable developers who have only a rudimentary knowledge of HTML and client-side scripting to build sophisticated Web pages.

But the story of componentization in ASP.NET doesn t end with server controls. ASP.NET supports a second type of component called the user control. A user control is a custom control built from HTML and server-side script. It s an intuitive and easily understood means for capturing and sharing functionality without resorting to the server-side includes (SSIs) so prevalent in ASP programming. And it s a mechanism for building reusable ASP.NET components that s simpler than writing full-blown server controls. A developer familiar with the Web Forms programming model can have a basic user control up and running in no time flat. Then he or she can instantiate that control in Web forms by using declarative tags much like those used to declare DataGrids and other server controls.

User controls enjoy three primary uses:

  • To factor out complex UI elements and convert them into reusable components

  • To create dynamic pages that are personalized for individual users

  • To facilitate output caching at the subpage level that is, to cache a page s static content while allowing other parts of the page to be rendered dynamically

This chapter is all about user controls what they are, how to write them, how to use them, and why you d want to use them in the first place. You ll see some real working examples of user controls, including one that implements Web navigation bars, and learn how to combine user controls with HTTP cookies to create personalized content. Finally, you ll learn how user controls can improve the performance of applications built around Web forms.

User controls are one of the most important facets of the Web Forms programming model so important, in fact, that time delayed in learning about them is time wasted. In the words of a famous American, let s roll.



Programming Microsoft  .NET
Applied MicrosoftNET Framework Programming in Microsoft Visual BasicNET
ISBN: B000MUD834
EAN: N/A
Year: 2002
Pages: 101

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