An ASP.NET page is defined as a file in a Web application with an .aspx file name extension with an HTML form element that specifies runat="server".
Developers can optionally specify an
directive or other directive (as appropriate to the type of page that you are creating), one or more Web server controls, and server code in the file.
The following table shows the directives that are supported by ASP.NET framework.
@ Page is used to defines page-specific (.aspx file) attributes used by the ASP.NET page parser and compiler.
<%@ Page attribute="value" [attribute="value"...] %>
Attributes/Values
Async
Makes the page an asynchronous handler (that is, it causes the page to use an implementation of IHttpAsyncHandler to process requests).
The default is
false.
AsyncTimeOut
Defines the time-out interval (in seconds) used when processing asynchronous tasks. The default is 45 seconds.
The value must be an integer.
AspCompat
When set to true, allows the page to be executed on a single-threaded apartment (STA) thread. This allows the page to call STA components, such as a component developed with Microsoft Visual Basic 6.0. Setting this attribute to true also allows the page to call COM+ version 1.0 components that require access to unmanaged Active Server Pages (ASP) built-in objects. These are accessible through the ObjectContext object or the OnStartPage method. The default is false.
AutoEventWireup
Indicates whether the page's events are autowired. true if event autowiring is enabled; otherwise, false. The default is true.
When
AutoEventWireup = true (by default), ASP.NET binds page events to methods using a naming convention of
Page_eventname.
For example, to create a handler for the page's Load event, you can create a method named
Page_Load. At compilation time, ASP.NET will find methods based on this naming convention and automatically perform the binding between the event and the method.
buffer
Determines whether HTTP response buffering is enabled.
true if page buffering is enabled (default).
ClassName
A string that specifies the name of the page class that will be dynamically compiled when the page is requested.
This value can be any valid class name and can include a fully qualified class name.
ClientTarget
Indicates the target user agent (typically, a Web browser such as Microsoft Internet Explorer) for which ASP.NET server controls should render content. This value can be any valid alias as defined within the <clientTarget> section of the application's configuration file.
CodeFile
Specifies a path to the referenced code-behind file for the page. This attribute is used together with the Inherits attribute to associate a code-behind source file with a Web page. The attribute is valid only for compiled pages.
CodeFileBaseClass
Specifies the type name of a base class for a page and its associated code-behind class. This attribute is optional, but when it is used the CodeFile attribute must also be present. Use this attribute when you want to implement a shared scenario, where you define common fields (and optionally, associated events) in a base class to reference the controls declared in a Web page.
CodePage
Indicates the value of the encoding scheme used for the response. The value is an integer that serves as an ID for the encoding scheme. For a list of possible CodePage IDs, see the Encoding class.
CompilationMode
Sets whether the page should be compiled, using a string that specifies one of several enumerated options. The default value is Always, so .aspx pages are compiled by default. For details, see the CompilationMode enumeration.
CompilerOptions
A string containing compiler options used to compile the page. In C# and Visual Basic, this is a sequence of compiler command-line switches. For more information about compiler options, see C# Compiler Options or Visual Basic Compiler.
ContentType
Defines the HTTP content type of the response as a standard MIME type. Supports any valid HTTP content-type string. For a list of possible values, search for MIME in the MSDN Library.
Culture
Indicates the culture setting for the page. The value of this attribute must be a valid culture ID. Note that the LCID and Culture attributes are mutually exclusive; if you use one of these attributes, you cannot use the other in the same page. For more information about possible culture values, see the CultureInfo class.
Debug
Indicates whether the page should be compiled with debug symbols. true if the page should be compiled with debug symbols; otherwise, false. Because this setting affects performance, you should only set the attribute to true during development.
Description
Provides a text description of the page. This value is ignored by the ASP.NET parser.
EnableEventValidation
Enables validation of events in postback and callback scenarios. true if events are being validated; otherwise, false. The default is true.
Page event validation reduces the risk of unauthorized postback requests and callbacks.
When the
enableEventValidation property is set to true, ASP.NET allows only the events that can be raised on the control during a postback request or callback.
With this model,
a control registers its events during rendering and then validates the events during the post-back or callback handling.
All event-driven controls in ASP.NET use this feature by default.
EnableSessionState
Defines session-state requirements for the page. true if session state is enabled; ReadOnly if session state can be read but not changed; otherwise, false. The default is true. These values are case-insensitive. For more information, see ASP.NET Session State.
EnableTheming
Indicates whether themes are used on the page. true if themes are used; otherwise, false. The default is true.
EnableViewState
Indicates whether view state is maintained across page requests. true if view state is maintained; otherwise, false. The default is true.
EnableViewStateMac
Indicates that ASP.NET should run a machine authentication check (MAC) on the page's view state when the page is posted back from the client. true if view state should be MAC checked; otherwise, false. The default is true.
ErrorPage
Defines a target URL for redirection if an unhandled page exception occurs.
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.
Inherits
Defines a code-behind class for the page to inherit. This can be any class derived from the Page class. This attribute is used with the CodeFile attribute, which contains the path to the source file for the code-behind class. The Inherits attribute is case-sensitive when using C# as the page language, and case-insensitive when using Visual Basic as the page language.
Language
Specifies the language used when compiling all inline rendering (<% %> and <%= %>) and code declaration blocks within the page. Values can represent any .NET Framework-supported language, including Visual Basic, C#, or JScript. Only one language can be used and specified per page.
LCID
Defines the locale identifier for the Web Forms page.
LinePragmas
Determines whether the runtime should generate line pragmas in the source code. These are compiler options that are often used by debugging tools to mark specific locations in a source file. true if line pragmas should be generated; otherwise, false.
MaintainScrollPositionOnPostback
Indicates whether to return the user to the same position in the client browser after postback. true if users should be returned to the same position; otherwise, false. The default is false.
MasterPageFile
Sets the path to the master page for the content page or nested master page. Supports relative and absolute paths.
ResponseEncoding
Indicates the name of the encoding scheme used for the HTTP response that contains a page's content. The value assigned to this attribute is a valid encoding name. for a list of possible encoding names, see the Encoding class. You can also call the GetEncodings method for a list of possible encoding names and IDs.
SmartNavigation
Indicates whether the page supports the smart navigation feature of Internet Explorer 5.5 or later. true if smart navigation is enabled; otherwise, false. The default is false.
Src
Specifies a path to a source file containing code that is linked to the page. In the linked source file, you can choose to include programming logic for your page either in a class or in code declaration blocks.
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.
This attribute is ignored by languages other than Visual Basic.
StyleSheetTheme
Specifies a valid theme identifier to use on the page. When the StyleSheetTheme attribute is set, individual controls can override the stylistic settings contained in a theme.
Thus a theme can provide an overall look for a site, while the settings contained in the StyleSheetTheme attribute enable you to customize particular settings on a page and its individual controls.
TargetSchema
Specifies the name of a schema that validates content on the page. This serves only a descriptive purpose; no actual validation is performed, and the attribute is ignored by the parser.
Theme
Specifies a valid theme identifier to use on the page. When the Theme attribute is set without using the StyleSheetTheme attribute, it overrides individual style settings on controls, enabling you to create a unified and consistent look on a page.
Title
Specifies a title for the page that is rendered within the HTML <title> tags in the response. The title can also be accessed programmatically as a property of the page. For details, see the Title property.
Trace
Indicates whether tracing is enabled. true if tracing is enabled; otherwise, false. The default is false. For more information, see ASP.NET Tracing.
TraceMode
Indicates how trace messages are to be displayed for the page when tracing is enabled. Possible values are SortByTime and SortByCategory. The default, when tracing is enabled, is SortByTime. For more information about tracing, see ASP.NET Tracing.
Transaction
Indicates whether transactions are supported on the page. Possible values are Disabled, NotSupported, Supported, Required, and RequiresNew. The default is Disabled.
UICulture
Specifies the user interface (UI) culture setting to use for the page. Supports any valid UI culture value.
ValidateRequest
Indicates whether request validation should occur. If true, request validation checks all input data against a hard-coded list of potentially dangerous values. If a match occurs, an HttpRequestValidationException exception is thrown. The default is true.
ViewStateEncryptionMode
Determines how view state is encrypted, with three possible enumerated values: Auto, Always, or Never. The default is Auto, meaning that view state will be encrypted if an individual control requests it. For more information, see the ViewStateEncryptionMode enumeration.
WarningLevel
Indicates the compiler warning level at which you want the compiler to treat warnings as errors, thus aborting compilation of the page. Possible warning levels are 0 through 4. For more information, see the WarningLevel property.
Reference: MSDN @Page.
@ Control is used to 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 ASP.NET User Controls (whose source code is contained in .ascx files).
<%@ Control attribute="value" [attribute="value"...] %>
Attributes/Values
AutoEventWireup
Indicates whether the control's events are autowired. true if event autowiring is enabled; otherwise, false. The default is true.
ClassName
A string that specifies the class name for the control that will be dynamically compiled when the user control is requested.
This value can be any valid class name and can include a fully qualified class name.
CodeFile
Specifies a path to the referenced code-behind file for the control. This attribute is used together with the Inherits attribute to associate a code-behind source file with a user control. The attribute is valid only for compiled controls.
CodeFileBaseClass
Specifies the type name of a base class for a user control and its associated code-behind class. This attribute is optional, but when it is used the CodeFile attribute must also be present. Use this attribute when you want to implement a shared scenario, where you define common fields (and optionally, associated events) in a base class to reference the controls declared in a user control.
CompilationMode
Sets whether the user control should be compiled, using a string that specifies one of several enumerated options. The default value is Always, so .ascx controls are compiled by default. For details, see the CompilationMode enumeration.
CompilerOptions
A string containing compiler options used to compile the control. In C# and Visual Basic, this is a sequence of compiler command-line switches. For more information about compiler options, see C# Compiler Options or Visual Basic Compiler.
Debug
Indicates whether the control should be compiled with debug symbols. true if the control should be compiled with debug symbols; otherwise, false. Because this setting affects performance, you should only set the attribute to true during development.
Description
Provides a text description of the control. This value is ignored by the ASP.NET parser.
EnableViewState
Indicates whether view state is maintained across control requests. true if view state is maintained; otherwise, false. The default is true.
Explicit
Determines whether the control 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.
Inherits
Defines a code-behind class for the control to inherit. This can be any class derived from the control class. This attribute is used with the CodeFile attribute, which contains the path to the source file for the code-behind class. The Inherits attribute is case-sensitive when using C# as the page language, and case-insensitive when using Visual Basic as the page language.
Language
Specifies the language used when compiling all inline rendering (<% %> and <%= %>) and code declaration blocks within the control. Values can represent any .NET Framework-supported language, including Visual Basic, C#, or JScript. Only one language can be used and specified per control.
LinePragmas
Determines whether the runtime should generate line pragmas in the source code. These are compiler options that are often used by debugging tools to mark specific locations in a source file. true if line pragmas should be generated; otherwise, false.
Src
Specifies a path to a source file containing code that is linked to the control. In the linked source file, you can choose to include programming logic for your control either in a class or in code declaration blocks.
Strict
Indicates that the control should be compiled using the Visual Basic Option Strict mode. true if Option Strict is enabled; otherwise, false. The default is false.
This attribute is ignored by languages other than Visual Basic.
TargetSchema
Specifies the name of a schema that validates content on the control. This serves only a descriptive purpose; no actual validation is performed, and the attribute is ignored by the parser.
WarningLevel
Indicates the compiler warning level at which you want the compiler to treat warnings as errors, thus aborting compilation of the control. Possible warning levels are 0 through 4. For more information, see the WarningLevel property.