Showing posts with label Title. Show all posts
Showing posts with label Title. Show all posts

Saturday, October 10, 2009

Directive Syntax Page

Directive Syntax

Directives are instructions used to specify settings (related to how a page should render and processed) used by the page and user control compilers when they process ASP.NET Web Forms page (.aspx) and user control (.ascx) files. These are the essential part of every ASP.NET Page or Control.

Directives can be located anywhere in an .aspx or .ascx file, but the standard practice is to include them at the beginning of the file (The advantage of using them at the top or the beginning of the file is that we need not to search them through out the file to make any minor change). Each directive can contain one or more attributes (paired with values, same as any HTML tag) that are specific to that directive.

Special Note:

The @ Page directive can be used only in .aspx files, and the @ Control directive can be used only in .ascx files.

The ASP.NET framework supports 11 types of directives and they are as follows.

@ Page: Can be included only in .aspx files. It defines page-specific attributes used by the ASP.NET page parser and compiler. Every .aspx files should include this @Page directive to execute. Throwing some light on important attributes of page directive

a. AspCompat:

Value: true || false.  By Default even if we don’t specify the value for AspCompat, it is set to false.
Purpose: Setting it to true will allow to the page to be executed on a single-threaded scenario.
For Example: The main cause when we set it to true is when we intend to use a component which was developed in VB 6.0; we can set this value to True.
Caution: Setting this attribute to true can cause page’s performance to degrade.

b. Language:

Value: Is a valid string which can represent any .NET-supported language, including VB, C#,  Pearl, Jscript any other .NET
Purpose: Tell the compiler about the language being used in the code-behind file.

c. AutoEventWireup:

Value: Can be true || False. By Default value is true.
Purpose: For every page in a .net website there is an automatic way to bind the events to their corresponding methods in the same .aspx file and code behind.

d. CodeFile:

Value: Any string which specifies the name of the code-behind file.
Purpose: Specifies the associated code-behind file of the page.

e. Title:

Value: Any String
Purpose: To set the page title, if it is different from what is specified in the master page.
f. Culture:

Value: string containing the culture value or auto.
Purpose: To specifies the culture setting of the page. If set to auto; it enables the page to automatically detect the culture required for the page.

g. ValidateRequest:

Value: True ||False The default is true.
Purpose: Indicates whether request validation should occur or not. In case of true, request validation checks all input data against a hard-coded list of potentially dangerous values. In case they match, an HttpRequestValidationException Class is thrown.
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.


h. Theme:

Value: any string
Purpose: To specify the theme for the page. This feature is introduced in Asp.Net 2.0.


i. SmartNavigation:

Value: True ||False The default value is false
Purpose: Specifies that the page should use smart navigation feature or not. Smart Navigation Feature enables a page to save the position after a postback. i.e. the page will returns the postback to current position of the page.

j. MasterPageFile:

Value: any String
Purpose: Specifies the location of the MasterPage file to be used with the current Asp.Net (.aspx) page.
k. EnableViewState:

Value: True ||False The default is true.
Purpose: Tells whether view state is maintained across page requests. true to maintain view state is; otherwise, false.

l. ErrorPage:

Value: Any string in URL format
Purpose: Specifies a target URL for redirection in case of an unhandled page exception occurs.
m. Inherits:

Value: any string
Purpose: Specifies a code-behind class name which the page will inherit. It can be any class which inherits the Page class.



There are also other attributes which are of seldom use such as Buffer, CodePage, ClassName, EnableSessionState, Debug, Description, EnableTheming, EnableViewStateMac, TraceMode, WarningLevel, etc.



An example of how a @Page directive looks



<Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Sample Page Title">


For More details Visit MSDN

Subscribe via email

Enter your email address:

Delivered by FeedBurner

MSDotnetMentor

MSDotnetMentor My Website http://msdotnetmentor.com