[Asp.net] registering user controls and Custom Controls

Source: Internet
Author: User
ArticleDirectory
    • Introduce
Introduce 1 <% @ Register tagprefix = " Scott " Tagname = " Header " SRC = " Controls/header. ascx "   %>
2 <% @ Register tagprefix = " Scott " Tagname = " Footer " SRC = " Controls/footer. ascx "   %>
3 <% @ Register tagprefix = " Controlvendor " Assembly = " Controlvendor "   %>
4
5 < Html >
6 < Body >
7 < Form ID = "Form1" Runat = "Server" >
8 < SCOTT: Header ID = "Myheader" Runat = "Server"   />
9 </ Form >
10 </ Body >
11 </ Html >

Note that the first two registration commands above are used to register User Controls (implemented in the. ascx file), and finally this is used to register and compileProgramSet. dll file. After registration, developers can declare these controls with the configured tagprefix and tagname anywhere on the page.

Advantages: The src attribute is used to clearly and intuitively locate the control definition;


Disadvantages: If your project has 100 pages that use user controls... one day, the Directory of user controls is changed.


Introduce in Web. config <? XML version = "1.0" ?>
< Configuration >
< System. Web >
< Pages >
< Controls >
< Add Tagprefix = "Scottgu" SRC = "~ /Controls/header. ascx" Tagname = "Header" />
< Add Tagprefix = "Scottgu" SRC = "~ /Controls/footer. ascx" Tagname = "Footer" />
< Add Tagprefix = "Controlvendor" Assembly = "Controlvendorassembly" />
</ Controls >
</ Pages >
</ System. Web >
</ Configuration >

Advantage: once declared, you can useTagprefixAndTagnameUse this control;
Disadvantages :......
In addition, for custom controls, there is a difference between dynamic and non dynamic: the class file of the former is located in ~ /App_code, and the Assembly attribute does not need to be specified; the latter generally stores the compiled DLL file in ~ /Bin directory. The Assembly attribute must be specified. Therefore, the Assembly attribute of the user control is optional. The namespace attribute is used to specify the namespace of the control in the dataset.
For user controls, the tagname and SRC attributes must be specified.

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.