Associate aliases with namespaces and class names to use concise notation in custom Server Control syntax.
<% @ Register tagprefix = "tagprefix" namespace = "namespace" assembly = "assembly" %>
<% @ Register tagprefix = "tagprefix" tagname = "tagname" src = "pathname" %>
Attribute
Tagprefix
The alias associated with the namespace.
Tagname
The alias associated with the class.
Namespace
The namespace associated with the tagprefix.
SRC
Location (relative or absolute) of the declarative user control file associated with the tagprefix: tagname pair ).
Assembly
The Assembly where the namespace associated with the tagprefix resides.
Note that the Assembly name does not include the file extension.
Remarks
If the @ register command is included in a page or user control, you can use the declarative custom Server Control syntax to customize the layout of the server control or user control.
Use the @ register command in the following cases.
Add the custom Asp.net server control to a page or user control by declaring it.
Add declarative user controls to pages or user controls.
For declarative user controls, use the tagname, tagprefix, and SRC attributes. When declaring a control on the page, the first two attributes are always used together in the form of tagprefix: tagname. The SRC property value can be a relative path from the application root directory to the user control source file, or an absolute path. We recommend that you use relative paths for ease of use. For example, assume that all application user control files are stored in the subdirectory/usercontrol of the application root directory. To include the user control in the usercontrol1.ascx file, add the following content to the @ register command:
Src = "~ /Usercontrol/usercontrol1.ascx"
Font size (~) The root directory of the application.
Note: If the user control and the page containing the control are in the same directory, the SRC property value should be the file name and extension of the. ascx file.
When a custom server control that has been compiled as a. dll file is included in the program, use the tagprefix with the Assembly and namespace attributes. If the namespace attribute is not included or an empty string is assigned to the attribute, a parser error occurs.
Warning when developing a custom Server Control, it must be included in the namespace. If it is not included in the namespace, the control cannot be accessed from the Asp.net page. For more information about developing custom Asp.net server controls, see develop simple Asp.net server controls.
Example
The following code snippet uses the @ register command to declare the tagprefix and tagname aliases of the server control and user control. The first command declares the mytag alias as the tag prefix of all controls residing in the mycompany: mynamespace namespace. The second command declares Acme: adrotator as the tagprefix: tagname pair of the user control in the file adrotator. acscx. Then, use an alias in the Custom Server Control syntax of the form to insert an instance for each server control.
<% @ Register tagprefix = "mytag" namespace = "mycompany: mynamespace" assembly = "myassembly" %>
<% @ Register tagprefix = "Acme" tagname = "adrotator" src = "adrotator. ascx" %>
<HTML>
<Body>
<Form runat = "server">
<Mytag: mycontrol id = "control1" runat = "server"/> <br>
<Acme: adrotator file = "myads. xml" runat = "server"/>
</Form>
</Body>
</Html>