Chapter 8

User Controls

What You Will Learn in This Chapter:

  • What user controls are, how they look, and why they are useful
  • How to create user controls
  • How to consume (or use) user controls in your pages
  • How you can improve the usefulness of user controls by adding coding logic to them

Wrox.com Code Downloads for this Chapter

You can find the wrox.com code downloads for this chapter on the Download Code tab at www.wrox.com/remtitle.cgi?isbn=1118311809. The code is in the Chapter 8 download.

In addition to the master pages, themes, and skins discussed in Chapter 6, ASP.NET 4.5 has another feature that enables you to create reusable and thus consistent blocks of information: user controls.

User controls enable you to group logically related content and controls together so they can be treated as a single unit in content pages, master pages, and inside other user controls. A user control is actually a sort of mini-ASPX page in that it has a markup section and, optionally, a Code Behind file in which you can write code for the control. Working with a user control is very similar to working with normal ASPX pages, with a few minor differences.

In versions of ASP.NET before 2.0, user controls were often used to create blocks of reusable functionality that had to appear on every page in the site. For example, to create a menu, you would create a user control and then add that control to each and every page in the site. Because of the ASP.NET support for master pages, you don't need ...

Get Beginning ASP.NET 4.5: in C# and VB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.