In Asp.net

Source: Internet
Author: User

<% @ Register src = "usercontrol/uccategorytree. ascx" tagname = "uccategorytree" tagprefix = "uc1" %>
<% @ Register tagprefix = "webdiyer" assembly = "aspnetpager" namespace = "Wuqi. webdiyer" %>

In the next paging function today, the instance code references the DLL file of the aspnetpager paging control that is very dear Niu Ren Yang Tao. This is a compiled DLL file with good functions, however, I am not very clear about this reference method. I finally explained it clearly!

First, we will attach a section in today's example for registering the control code:

<% @ Register src = "usercontrol/uccategorytree. ascx" tagname = "uccategorytree" tagprefix = "uc1" %>

// Note that the above sentence references a user control and registers the user control to the current page for use. The tagname attribute and the src attribute must be paired, only the tagname value is written, and compilation fails without SRC.
<% @ Register tagprefix = "webdiyer" assembly = "aspnetpager" namespace = "Wuqi. webdiyer" %>

// This is the registration statement of the aspnetpager paging control.

----------------- The following is an online explanation -----------------

<% @ 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 custom ASP. NET Server controls to pages or user controls by declaring them.

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 user controls in the usercontrol1.ascx file, go
The @ register command contains the following content:

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 developing 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 runat = "server"/> <br>

<Acme: adrotator file = "myads. xml" runat = "server"/>

</Form>

</Body>

</Html>

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.