ASP.NET 4.0, Part 6: New Page Directive Attributes
Welcome to part 6 of my tour through ASP.NET 4.0 [http://blog.hmobius.com/post/2010/02/09/ASPNET-40-Cometh.aspx]. 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
ASP.NET 4.0 brings with it six new attributes for the @Page directive, as follows:
- ClientIDMode [http://msdn.microsoft.com/en-gb/library/system.web.ui.clientidmode(VS.100).aspx] 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 [http://msdn.microsoft.com/en-gb/library/system.web.ui.page.clienttarget(VS.100).aspx] overrides the automatic browser capabilities detection we saw in part 5 [http://blog.hmobius.com/post/2010/02/19/ASPNET-40-Part-5-Ill-Name-That-Browser-In-One.aspx] and let’s you specify explicitly what browser capabilities the ASP.NET engine should target when rendering the page. * MetaDescription [http://msdn.microsoft.com/en-gb/library/system.web.ui.page.metadescription(VS.100).aspx] sets the Page’s new MetaDescription property which is then rendered in the HTML description tag. * MetaKeywords [http://msdn.microsoft.com/en-gb/library/system.web.ui.page.metakeywords(VS.100).aspx] sets the Page’s new MetaKeywords property which is then rendered in the HTML 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 [http://msdn.microsoft.com/en-us/library/aa713983(VS.71).aspx]. Note that TargetSchema is for descriptive purposes only; no actual validation is performed, and the attribute is ignored by the parser. * ViewStateMode [http://msdn.microsoft.com/en-gb/library/system.web.ui.control.viewstatemode(VS.100).aspx] 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!Posted on February 22, 2010 #Geek Stuff