How to Register Custom Controls?

A user control is a kind of composite control that works much like an ASP.NET Web page. You can add existing Web server controls and mark-up to a user control, and define properties and methods for the control. You can then embed them in ASP.NET Web pages, where they act as a unit.

You can register a custom server control to a Web page using the @Register directive. Create an @ Register directive that includes:

  1. A TagPrefix attribute, which associates a prefix with the user control. This prefix will be included in opening tag of the user control element.

  2. A TagName attribute, which associates a name with the user control. This name will be included in the opening tag of the user control element.

  3. A Src attribute, which defines the virtual path to the user control file that you are including.

< %@ Register TagPrefix="" TagName="" Src="" % >

The user control is in the file "uploader.ascx" in the Controls folder. In the page, the control is registered to use the prefix "up" and the tag name "Uploader".

< %@ Register TagPrefix="up" TagName="Uploader" Src="~/Controls/uploader.ascx" % >

The Src attribute value can be either a relative or an absolute path to the user control source file from your application's root directory.

How to use?

In the body of the Web page, declare the user control element inside the form element. Optionally, if the user control exposes public properties, set the properties declaratively. Also, the user control properties MinValue and MaxValue are set declaratively.

Register Custom Controls in