O'Reilly logo

ASP.NET by Example by Steven A. Smith

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating ASP.NET User Controls

We create user controls much the same way that we create normal Web forms in ASP.NET; however, we normally denote that a file is to be used as a control by saving it with an .ascx file extension. Let's look at an example of a simple user control.

<asp:label text="Welcome to ASP.NET User Controls" runat="Server"/>

Yes, that's it. That's our entire control. Note that it's nothing more really than a Web form fragment, and in our control definition file we do not include <html>, <head>, <body>, or <form runat="server"> tags. Listing 9.1 shows how we use our control on a Web form.

Listing 9.1. Implementing the User Control on a Web Form (91.aspx)
 <%@ Page language="c#"%> <%@ Register TagPrefix="ASPNETByExample" TagName="Welcome" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required