Welcome to part 6 of my tour through ASP.NET 4.0. Over the next few posts we’ll be looking at some of the changes made to the standard webforms page. For today, we’ll start at the top and look at the new Page directive attributes in this release in anticipation of some future posts.

The default @Page directive added to the top of every new webform generated by Visual Studio 2010 has not changed from that in VS2008. It still has the standard four attributes.

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

Indeed, all 42 (yes, 42!) attributes from .NET 2.0 have been kept for backwards compatibility as you might expect.  You might be surprised how many there are: some present per-page overrides to the <pages> element in your web.config files, others how the page should operate, and others how the code-behind the page fits into the code hierarchy of your site. A brief explanation of them all can be found here.

ASP.NET 4.0 brings with it six new attributes for the @Page directive, as follows:

  • ClientIDMode sets the method ASP.NET will use to render the IDs for every element on the page. Possible values are AutoID (the default), Predictable, Static and Inherit. We’ll investigate how they each work in a forthcoming post.
  • ClientTarget overrides the automatic browser capabilities detection we saw in part 5 and let’s you specify explicitly what browser capabilities the ASP.NET engine should target when rendering the page.
  • MetaDescription sets the Page’s new MetaDescription property which is then rendered in the HTML <meta> description tag.
  • MetaKeywords sets the Page’s new MetaKeywords property which is then rendered in the HTML <meta> keywords tag.
  • TargetSchema identifies the schema that validates content on the page when being designed. It’s purpose is similar to a property of the same name in .NET 1.1. Note that TargetSchema is for descriptive purposes only; no actual validation is performed, and the attribute is ignored by the parser.
  • ViewStateMode specifies whether the page’s ViewState is controlled by an opt-in or an opt-out (the default) model. As with ClientIDMode, we’ll investigate this further in part 7.

In tomorrow’s post, we’ll look in more depth at the new options for controlling ViewState on a page. Happy coding!