Adding a Web UserControl to your ASP.NET projects

Top  Previous  Next

 

An ASP.NET user control is a group of one or more static HTML elements or server controls that encapsulate a piece of functionality.

Examples of a user control could simply be an extension of an existing server control(s) functionality (such as a calendar control that stores the date in a text box or an image control that can be rotated). Or, it could consist of several elements that work and interact together to get a job done (such as several controls grouped together that gather information about a user's sales history and access level).

In either case, a user control typically resides on a page with other elements. This breakup of functionality could be the basis of an entire application built with independent and reusable user controls. The controls could then be dynamically loaded into different areas of the page.

 

To add a custom User Control to your ASP.NET project, right-click on the project node located in the Solution Explorer. Select Add New Item from the popup menu, and select the Web User Control from the Quick Starts list.

 

This will create an ASCX and a "code behind" CLN file. The Design tab for the ASCX file should now be enabled (visible) and you can populate and code your user control from this point forward.