User Control Basics

To get started, let’s build a simple User Control, MyControl.ascx, and an ASP.NET page that consumes it, MyPage.aspx.

MyControl

Most of the time, User Controls will contain dynamic elements, but that’s not always the case. For instance, you might create a User Control to display copyright information at the bottom of each page in your web application. Likewise, the User Control MyControl will start off with just static content. Right now, you’ll be concerned with the issues surrounding the basic plumbing of User Controls, as you can see in Listing 11.1.

Listing 11.1. MyControl— Basics
<%@ Control Language="C#" %> 

This is MyControl. 

MyPage

Now that you have a simple User Control built, you can implement it in an ASP.NET page. ...

Get Debugging ASP.NET 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.