C #: @ register command, custom control

Source: Internet
Author: User
Tags tagname
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" %>

Write an example:

Above the HTML Tag, write instructions

<%@ Register TagPrefix="cc1" Namespace="abc.WebControls" Assembly="<span style="font-family: Arial, Helvetica, sans-serif;">abc</span><span style="font-family: Arial, Helvetica, sans-serif;">.WebControls.ComboBox" %></span>

Write in the Div or table of the control to be written.

<td style="width: 80px; height: 18px">                    <cc1:ComboBox ID="css1" runat="server" Width="109px" Rows="5">                    </cc1:ComboBox></td>


Attribute
Alias associated with the namespace
Alias associated with the tagname and class
The namespace associated with the tagprefix.
SRC and tagprefix: the location (relative or absolute) of the associated declarative user control file of the tagname ).

The assembly in which the namespace associated with assembly and tagprefix reside.

PS: 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 sub-directory \ 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>


Reference: http://blog.sina.com.cn/s/blog_4c9ed49d0100a8cl.html

PS: This article is only used for recording learning.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.