Please navigate to the bottom of the page for Table of Contents

Friday, May 27, 2011

ASP.NET @ Page directive

Every ASP.NET generally begins with the @ Page directive. This defines page-specific attributes used by the ASP.NET page parser and compiler and can be included only in .aspx files. By default, Visual Studio creates a page directive as shown below (when you use the default web application template):

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>

This directive can be used only in Web Forms pages. You can include only one @ Page directive per .aspx file. Further, you can define only one Language attribute per @ Page directive, because only one language can be used per page.The Page directive is made of many attributes. Let’s review a few of the important ones:

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.

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.

Sets the path to the master page for the content page or nested master page. Supports relative and absolute paths.

Indicates whether the page's events are autowired. true if event autowiring is enabled; otherwise, false.

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.

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

In addition to the attributes generated by default, you should also know about the following properties. They are a favorite of interviewers (they are either obscure, or ASP.NET 4 specific or they just like it).

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.

Defines the HTTP content type of the response as a standard MIME type. Supports any valid HTTP content-type string.

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.

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.

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.


  1. I gone through your article, its really interesting. Dot net is most used programming language for creating highly dynamic desktop and web application. Dot net programming language has created massive revolution in software development industry. Best Dot Net Training

  2. Thank you so much..i have to really helpful for your sharing information..

    Information Training in Chennai | Oracle DBA Training in Chennai

  3. This comment has been removed by the author.


  4. Oracle DBA Training in Chennai
    Thanks for sharing this informative blog. I did Oracle DBA Certification in Greens Technology at Adyar. This is really useful for me to make a bright career..

  5. Excellent information with unique content and it is very useful to know about the information based on blogs. Hadoop Training in Chennai

  6. I found some useful information in your blog,it was awesome to read, thanks for sharing this great content to my vision, keep sharing..selenium Training in Chennai

  7. Really awesome blog. Your blog is really useful for me. Thanks for sharing this informative blog. Keep update your blog.SAP Training in Chennai

  8. Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing.Nice article i was really impressed by seeing this article, it was very interesting and it is very useful for me.. Android Training in Chennai

  9. Wonderful tips, very helpful well explained. Your post is definitely incredible. I will refer this to my friend.SalesForce Training in Chennai

  10. very nice blogs!!! i have to learning for lot of information for this sites...Sharing for wonderful information.Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing.Oracle DBA Training in Chennai

  11. This is really an awesome article. Thank you for sharing this.It is worth reading for everyone. Visit us:
    Oracle Training in Chennai

  12. fantastic presentation .We are charging very competitive in the market which helps to bring more oracle professionals into this market. may update this blog . Datastage Training In Chennai

  13. I have read your blog and I got very useful and knowledgeable information from your blog. It’s really a very nice article Spring training In Chennai

  14. i gain the knowledge of and industry oriented coaching available from greens technology chennai in Adyar may visit.Sharepoint Training In Chennai

  15. once again sharing this informative blog .It uses a graphical notation to construct data integration solutions and is available in various versions may visit greens technology chennai in adyaroracle dba training In Chennai

  16. i wondered keep share this sites .if anyone wants realtime training Greens technolog chennai in Adyar visit this blog..performance tuning training In Chennai

  17. Usually I am able to add links to other websites or pages within Informix Training In Chennai

  18. Thanks for the useful information that was provided, Get more ideas on Sql Server Dba Training In Chennai

  19. Thanks for sharing this informative blog. If anyone wants to get Struts Training In Chennai

  20. It was really a wonderful article and I was really impressed by reading this blog.Oracle sql plsql Training In Chennai

  21. This page is dedicated for our Greens Technologies Reviews by our students. Please give your reviews here, Qlikview Training In Chennai

  22. I like this post, and i learn new software product. thank to share with us Oracle Rac Training In Chennai

  23. This is very useful information. Thanks for sharing.Teradata Training In Chennai

  24. i gain the knowledge and industry oriented coaching available from greens technology chennai visit.Advanced oracle sql tuning Training In Chennai

  25. Very nice blogs!!! i have to learning for lot of information for this sites...
    android Training in Chennai | Oracle Training in Chennai