Condividi tramite


controls Element for pages (ASP.NET Settings Schema)

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

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

<controls> 
   <add /> 
</controls>

Attributes and Elements

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

Attributes

None.

Child Elements

Element Description

add

Optional element.

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

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 globally, such as ASP.NET directives for pages and controls that are within the scope of the configuration file.

Remarks

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 lets you 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" 
            source="MyControl.ascx"/>
      </controls>
   </pages>

Element Information

Configuration section handler

PagesSection

Configuration member

Controls

TagPrefixCollection

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 2003 or Visual Studio 2005

See Also

Tasks

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

Reference

pages Element (ASP.NET Settings Schema)
add Element for controls for pages (ASP.NET Settings Schema)
tagMapping Element for pages (ASP.NET Settings Schema)
namespaces Element for pages (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
PagesSection

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