Page directive in Asp.Net

<%@Page attribute=”value” [attribute=”value”…] %>

ASP.NET pages usually contain directives that allow you to specify page properties and configuration information for the page. The directives are used by ASP.NET as instructions for how to process the page, but they are not rendered as part of the markup that is sent to the browser.

The @ Page directive, which allows you to specify many configuration options for the page, including the following:
• The server programming language for code in the page.
• Whether the page is a page with server code directly in the page, which is called a single-file page, or whether it is a page with code in a separate class file, which is called a code-behind page. In the previous example, the page is a single-file page; the code is directly in the page, and the @ Page directive does not include information about linked class files.
• Debugging and tracing options.
• Whether the page has an associated master page and should therefore be treated as a content page.

***If you do not include an @ Page directive in the page, or if the directive does not include a specific setting, settings are inherited the from the configuration file for the Web application (the Web.config file) or from the site configuration file (the Machine.config file).

In addition to including an @ Page directive, you can include other directives that support additional page-specific options. Other common directives include the following:
@Import This directive allows you to specify namespaces that you want to reference in your code.
@OutputCache This directive allows you to specify that the page should be cached, along with parameters for when and how long to cache the page.
@Implements This directive allows you to specify that the page implement a .NET interface.
@Register This directive allows you to register additional controls for use on the page. The @ Register directive declares the control’s tag prefix and the location of the control’s assembly. You must use this directive if you want to add user controls or custom ASP.NET controls to a page.

Certain types of ASP.NET files use a directive other than @ Page. For example, ASP.NET master pages use an @ Master directive, and ASP.NET user controls use an @ Control directive. Each directive allows you to specify different options that are appropriate for the file.

Attributes of Page Directive:
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. For more information, see ASP.NET Web Server Control Event Model.

Buffer
Determines whether HTTP response buffering is enabled. true if page buffering is enabled; otherwise, false. The default is true.

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. If a value for this attribute is not specified, the class name for the compiled page is based on the page’s file name and uses the default namespace ASP. If a value for the ClassName attribute is specified without a full namespace, then the namespace ASP is used, combined with the specified class name to create a fully qualified class name.

Another page can reference the class name assigned to the first page by using the @ Reference directive.

ClientIDMode
Specifies the algorithm to use to generate ClientID values for controls. The default value is Predictable. The default value for controls is Inherit. Therefore, the default algorithm for controls in a page is determined by the ClientID setting of the page. A different default value can be set in the pages element of the Web.config file. For more information about the algorithms, see the ClientIDMode class.

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 section of the application’s configuration file. For more information, see the ClientTarget property.

CodeBehind
Specifies the name of the compiled file that contains the class associated with the page. This attribute is not used at run time. This attribute is used for Web application projects. The CodeFile attribute is used for Web site projects. For more information about Web project types in Visual Studio, see Web Application Projects versus Web Site Projects.

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. This attribute is used for Web site projects. The CodeBehind attribute is used for Web application projects. For more information about Web project types in Visual Studio, see Web Application Projects versus Web Site Projects.

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. Because of the ASP.NET code generation model, if you defined the fields in a base class without using this attribute, at compile time new member definitions would be generated for the controls declared in the Web page (within a separate partial class stub), and your desired scenario would not work. But if you use the CodeFileBaseClass attribute to associate the base class with the page, and you make your partial class (its name is assigned to the Inherits attribute and its source file is referenced by the CodeFile attribute) inherit from the base class, then the fields in the base class will be able to reference the controls on the page after code generation.

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.

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, see the Culture property and 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
The EnableEventValidation attribute indicates whether event validation should be performed. The default value is true.
[ConfigurationPropertyAttribute(“enableEventValidation”, DefaultValue = true)]
public bool EnableEventValidation { get; set; }

When the EnableEventValidation property is set to true, ASP.NET validates that a control event originated from the user interface that was rendered by that control. A control registers its events during rendering and then validates the events during postback or callback handling.

For example, if a list control includes options numbered 1, 2, or 3 when the page is rendered, and if a postback request is received specifying option number 4, ASP.NET raises an exception. All event-driven controls in ASP.NET use this feature by default.

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. It is strongly recommended that you do not disable event validation. Before disabling event validation, you should be sure that no postback could be constructed that would have an unintended effect on your application.

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.

EnableTheming
Indicates whether themes are used on the page. true if themes are used; otherwise, false. The default is true.

EnableViewState
Specifies whether view state is maintained across page requests. This value is true if view state is maintained, or false if view state is not maintained. The default is true. Even if this property is set to true, view state will not be maintained for a control if any of the following conditions apply:
The control’s EnableViewState property is set to false. The control’s ViewStateMode property is set to Disabled or the control inherits the Disabled value.

For more information about view state and control state, see the Control.EnableViewState property.

EnableViewStateMac
Indicates that ASP.NET should verify message authentication codes (MAC) in 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. A view-state MAC is an encrypted version of the hidden variable that a page’s view state is persisted to when sent to the browser. The MAC is used to verify that view state has not been tampered with on the client.

ErrorPage
Defines a target URL for redirection if an unhandled page exception occurs. For more information, see the ErrorPage property.

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. If the Inherits attribute does not contain a namespace, ASP.NET checks whether the ClassName attribute contains a namespace. If so, ASP.NET attempts to load the class referenced in the Inherits attribute using the namespace of the ClassName attribute. (This assumes that the Inherits attribute and the ClassName attribute both use the same namespace.)
For more information about code-behind classes, see ASP.NET Web Page Code Model.

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. For more information, see the MasterPageFile property.

MetaDescription
Sets the MetaDescription property. If the page markup also includes a “description” meta element, the value in the @ Page directive overrides the value in markup.

MetaKeywords
Sets the MetaKeywords property. If the page markup also includes a “keywords” meta element, the value in the @ Page directive overrides the value in markup.

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. In ASP.NET version 2.0 and later versions, the SmartNavigation property is obsolete. Use the SetFocus method and the MaintainScrollPositionOnPostback property instead.

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. You can use the Src attribute to link build providers to the page. For more information, see the BuildProvider class. Also, in versions of ASP.NET prior to 2.0, the Src attribute was used as an alternative way to link a code-behind file to a page. In ASP.NET 2.0, the preferred approach to linking a code-behind source file to a page is to use the Inherits attribute to specify a class, along with the CodeFile attribute to specify the path to the source file for the class.

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.

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. For more information, see the Theme property.

Title
Specifies a title for the page that is rendered within the HTMLtags 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 Overview and the Trace property.

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

Transaction
Indicates whether COM+ 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. For more information, see the UICulture property.

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. This feature is enabled in the machine configuration file (Machine.config). You can disable it in your application configuration file (Web.config) or on the page by setting this attribute to false.

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.

ViewStateMode
Specifies the ViewStateMode property value that will take effect for a control when the ViewStateMode property of the control is Inherit. The default ViewStateMode value for a page is Enabled. The ViewStateMode and EnableViewState properties determine whether view state is maintained for controls on a page. For more information, see the EnableViewState property and the ViewStateMode property.

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.

Advertisements

21 thoughts on “Page directive in Asp.Net

  1. hey.. it’s really fantastic , I am .net programmer and I know it’s really hard to explain and write something like that you have written… great job… 🙂

    Like

  2. Hi there would you mind stating which blog platform you’re using? I’m planning to start my own blog soon but I’m having a difficult time selecting between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your layout seems different then most blogs and I’m looking for something unique.
    P.S My apologies for getting off-topic but I had to
    ask!

    Like

  3. You really make it seem so easy with your presentation but I find this
    topic to be actually something which I think I would never understand.
    It seems too complex and extremely broad for me. I am looking forward for your next post,
    I’ll try to get the hang of it!

    Like

  4. I think that what you said was actually very reasonable.

    But, think about this, suppose you added a little content?
    I am not saying your information is not solid, but suppose you added a post title that grabbed folk’s attention? I mean Page directive in Asp.Net | Code World Technology is a little boring. You might peek at Yahoo’s home
    page and watch how they create news titles to grab people to click.
    You might try adding a video or a pic or two to get
    people interested about everything’ve got to say. In my opinion, it would make your website a little livelier.

    Like

  5. You really make it appear really easy along
    with your presentation but I in finding this topic to be really one thing which I believe I would never understand.
    It seems too complex and extremely huge for me. I’m having a look ahead in your subsequent submit, I will attempt to get the cling of it!

    Like

  6. Hmm it looks like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I wrote and say, I’m thoroughly enjoying your blog.
    I too am an aspiring blog writer but I’m still new to the whole thing. Do you have any tips and hints for inexperienced blog writers? I’d definitely appreciate it.

    Like

  7. Attractive part of content. I simply stumbled upon your web site and
    in accession capital to claim that I get in fact loved account your weblog posts.
    Any way I’ll be subscribing to your augment or even I fulfillment you get right of entry to constantly quickly.

    Like

  8. I’m not that much of a online reader to be honest but your blogs really
    nice, keep it up! I’ll go ahead and bookmark your site to come back later. Cheers

    Like

  9. I simply want to mention I am beginner to blogs and definitely savored this web blog. Very likely I’m likely to bookmark your blog post . You actually have excellent stories. Kudos for sharing your website page.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s