asp.net.ph

Skip Navigation LinksHome > ASP.NET Web Forms > Web Forms Server Controls > Web Forms Server Controls overview

Web Forms Server Controls Overview

HTML Server Controls   Web Server Controls   Validation Controls   User Controls


User Controls

In addition to the built-in ASP.NET server controls, you can also use, with slight modification, any Web Forms page within another, somewhat similar to using server-side includes.

The main difference is that the imported page is treated as a server control, that is completely programmable like any other ASP.NET server control.

A Web Forms page used as a server control is called a user control for short. In earlier releases of ASP.NET, they were referred to as pagelets, which is what they are, technically. In this workshop, both terms are used interchangeably, and refer to the same thing.

NOTE: ASP.NET files that are to be used as user controls must have the filename extension .ascx. This ensures that the user control file cannot be requested as a standalone Web Forms page.

User controls are included in a Web Forms page using the @ Register directive:

<%@ Register tagPrefix="myCtrls" tagName="myHeader" Src="myHeader.ascx" %>
  • The tagPrefix specifies a unique namespace for the user control.
  • The tagName is the unique name that you assign to the user control itself. This provides a mechanism to differentiate multiple pagelets contained within the same Web Forms page.
  • The Src attribute refers to the location of the pagelet file. If the file resides in a folder other than where the containing .aspx page is, the attribute must point to the virtual file path — for example /asp.net.ph/shared/myHeader.ascx.

After registering the user control, you can employ the pagelet anywhere in the containing page, just like any other server control, using the following notation:

<myCtrls:myHeader runat="server" />

The following example shows two simple user controls imported into another Web Forms page.

The header pagelet includes the site’s logo and a simple script to display the current date and time, while the footer pagelet simply renders static content with a mailto: hyperlink.

User Control Syntax Example
Run Sample | View Source

In this workshop, you will encounter other examples of using pagelet controls, details of each taken up in a corresponding tutorial. For now simply note that the real power of user controls lies not only in their reusability, but more so in their programmability, as you shall later see.

And in case you haven’t noticed, the headers and side bars in each of the main sections of this workshop, and the footer below that appears in every page, are all done via simple user controls.

See Also

Controls You Can Use on Web Forms   Server Controls Templates   Server Controls and CSS Styles   Programming Web Forms Server Controls


Back to top


© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note