Chapter 8User Controls


  • 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


You can find the code downloads for this chapter on the Download Code tab at The code is in the Chapter 8 folder.

In addition to the master pages, themes, and skins discussed in Chapter 6, ASP.NET 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.

You typically use a User Control for content that gets used in a few pages in your site. For example, you can build a user control that displays a banner that is shown on some, but not all pages, as you’ll see in this chapter.

By the end of this chapter, you’ll have a firm understanding of what user controls are and how they work, enabling you to create functional, ...

Get Beginning ASP.NET 4.5.1: in C# and VB now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.