ArticleDirectory
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.