Compartilhar via


@ Control

Defines user-control (.ascx file) specific attributes that are used by the ASP.NET page parser and compiler. This directive can be used only with user controls.

<%@ Control attribute="value" [attribute="value" ... ] %>

Attributes

  • AutoEventWireup
    Indicates whether the page's events are autowired. true if event autowiring is enabled; otherwise, false. The default is true. For more information, see Web Server Control Event Model.

  • ClassName
    Specifies the class name for the page that will be dynamically compiled automatically when the page is requested. This value can be any valid class name but should not include a namespace.

  • CompilerOptions
    A string containing compiler options used to compile the user control. In C# and Visual Basic .NET, this is a sequence of compiler command-line switches.

  • Debug
    Indicates whether the page should be compiled with debug symbols. true if the page should be compiled with debug symbols; otherwise, false.

  • Description
    Provides a text description of the page. Supports any string description.

  • EnableViewState
    Indicates whether view state for the user control is maintained across page requests. true if view state is maintained; otherwise, false. The default is true.

  • Explicit
    Determines whether the page is compiled using the Visual Basic Option Explicit mode. true indicates that the Visual Basic explicit compile option is enabled and that all variables must be declared using a Dim, Private, Public, or ReDim statement; otherwise, false. The default is false.

    Note   This attribute is ignored by languages other than Visual Basic .NET. Also, this option is set to true in the Machine.config configuration file. For more information, see Machine Configuration Files.

  • Inherits
    Defines a code-behind class for the user control to inherit. This can be any class derived from the UserControl class. For information about code-behind classes, see Web Forms Code Model.

  • Language
    Specifies the language used when compiling all inline-rendering (<% %> and <%= %>) and server-side script blocks within the user control. Values can represent any .NET-supported language, including Visual Basic, C#, or JScript .NET.

  • Strict
    Indicates that the page should be compiled using the Visual Basic Option Strict mode. true if Option Strict is enabled; otherwise, false. The default is false.

    Note   This attribute is ignored by languages other than Visual Basic .NET.

  • Src
    Specifies the source file name of the code-behind class to dynamically compile when the user control is requested. You can choose to include programming logic for your page either in a code-behind class or in a code declaration block in the .ascx file.

    Note   RAD designers, such as Visual Studio .NET, do not use this attribute. Instead, they precompile code-behind classes and then use the Inherits attribute.

  • WarningLevel
    Indicates the compiler warning level at which you want the compiler to abort compilation for the user control. Possible values are 0 through 4. For more information, see the CompilerParameters.WarningLevel Property property.

Remarks

This directive can be used only in user controls. User controls are defined in files with the .ascx extension. You can include only one @ Control directive per .ascx file.

Example

The following code instructs the ASP.NET page compiler to use Visual Basic as the inline code language and disables saving view state across HTTP requests using the EnableViewState attribute.

<%@ Control Language="VB" EnableViewState="false" %>

See Also

ASP.NET Web Forms Syntax | Web Forms User Controls | Directive Syntax