Freigeben über


add Element for controls for pages (ASP.NET Settings Schema) 

Adds a tag prefix to the collection of tag prefixes that are used during pre-compilation.

This element is new in the .NET Framework version 2.0.

<add
   assembly="assembly"
   namespace="namespace"
   src="file path"
   tagName="tag name"
   tagPrefix="tag prefix"
>

Attributes and Elements

The following sections describe attributes, child elements, and parent elements.

Attributes

Attribute Description

assembly

Optional String attribute.

Specifies the name of the assembly that contains the COM control implementation and requires that the namespace attribute is also set.

namespace

Optional String attribute.

Specifies the namespace that is associated with the tag prefix and requires that the assembly attribute is also set, if the COM control is not located in the application code directory.

src

Optional String attribute.

Specifies the name of the file that contains the user control and requires that the tagName attribute is also set.

tagName

Optional String attribute.

Specifies the name of the control to use in the page and requires that the src attribute is also set.

tagPrefix

Required String attribute.

Specifies the tag prefix that is being mapped to a source file or namespace and assembly. This attribute requires one of the following combinations of other attributes:

  • namespace to define a COM control, if the control is in the application code directory.

  • namespace and assembly to define a COM control.

  • tagName and src to define a user control.

Inherited attributes

Optional attributes.

Attributes inherited by all section elements.

Child Elements

None.

Parent Elements

Element Description

configuration

Specifies the required root element in every configuration file that is used by the common language runtime and the .NET Framework applications.

system.web

Specifies the root element for the ASP.NET configuration settings in a configuration file and contains configuration elements that configure ASP.NET Web applications and control how the applications behave.

pages

Defines page-specific configuration settings, such as global ASP.NET directives, for pages and controls that are within the scope of the configuration file.

controls

Defines a collection of register directives and the namespaces where the tag prefixes reside.

Remarks

The add element adds a tag prefix to the collection of tag prefixes in the controls element that are used during pre-compilation.

The controls element defines a collection of register directives and the namespaces where the tag prefixes reside. This element corresponds to the @ Register directive on an ASP.NET page. The @ Register directive allows you to specify the tag prefix for a user control.

Tag prefixes associate a namespace in ASP.NET to the assemblies and namespaces that must be included for COM and user controls to work correctly. The following information is useful when configuring the controls element:

  • If applied to a user control, you must define the tagPrefix, tagName, and source attributes of the add child element.

  • If applied to a custom control, you must define the tagPrefix, namespace, and assembly attributes of the add child element. The assembly attribute is not required, if the control is in the application code directory.

You can use the same tagPrefix value to map to multiple assemblies or namespaces.

Default Configuration

The following default controls element is configured in the root Web.config file.

<pages>
   <controls>
      <add 
         tagPrefix="asp" 
         namespace="System.Web.UI.WebControls.WebParts" 
         assembly="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
      />
   </controls>
   <!-- Other elements -->
</pages>

Example

The following code example demonstrates how to specify values declaratively for several attributes of the controls element, which can also be programmatically accessed as members of the TagPrefixInfo class.

   <pages>
      <controls>
         <!—- Searches all linked assemblies for the namespace -->
         <add 
            tagPrefix="MyTags1" 
            namespace="MyNameSpace"/>
         <!-- Uses a specified assembly -->
         <add 
            tagPrefix="MyTags2"
            namespace="MyNameSpace" 
            assembly="MyAssembly"/>
         <!-- Uses the specified source for the user control -->
         <add 
            tagprefix="MyTags3" 
            tagname="MyCtrl" 
            src="controls/MyControl.ascx"/>
      </controls>
   </pages>

Element Information

Configuration section handler

PagesSection

Configuration member

Add

Configurable locations

Machine.config

Root-level Web.config

Application-level Web.config

Virtual or physical directory–level Web.config

Requirements

Microsoft Internet Information Services (IIS) version 5.0, 5.1, or 6.0

The .NET Framework version 2.0

Microsoft Visual Studio 2005

See Also

Tasks

How to: Configure Specific Directories Using Location Settings
How to: Lock ASP.NET Configuration Settings

Reference

controls Element for pages (ASP.NET Settings Schema)
pages Element (ASP.NET Settings Schema)
system.web Element (ASP.NET Settings Schema)
configuration Element (General Settings Schema)
@ Page
@ Register
System.Configuration
System.Web.Configuration
Controls
TagPrefixCollection
Add

Concepts

ASP.NET Configuration File Hierarchy and Inheritance
Securing ASP.NET Configuration

Other Resources

General Configuration Settings (ASP.NET)
ASP.NET Configuration Settings
Configuring ASP.NET Applications
ASP.NET Configuration API