ASP.NET Technical Articles Building ASP.NET 2.0 Web Sites Using Web Standards Stephen Walther SuperExpert.com Applies to: Microsoft ASP.NET 2.0 Microsoft Visual Studio 2005 Microsoft Visual Web Developer Summary: Microsoft ASP.NET 2.0 has many features to help you design and build Web sites that are compliant with XHTML and accessibility standards. This article looks at how and why you should be building these standards-compliant sites. (78 printed pages) Contents Introduction Building XHTML Web Sites Versions of the XHTML Standard Creating XHTML Pages XHTML and ASP.NET Controls Validating XHTML Pages XHTML and DOCTYPE Switching XHTML and MIME Types Configuring XHTML Conformance Accessibility Standards Accessibility Improvements in ASP.NET 2.0 Creating Accessible Images Creating Accessible Forms Creating Accessible Navigation Creating Accessible Data Creating Accessible XHTML Creating Accessible Scripts Validating Pages for Accessibility Accessing the Amazon Web Services The Default Page XHTML Features of the Default Page Accessibility Features of the Default Page The Search Page XHTML Features of the Search Page Accessibility Features of the Search Page The Master Page XHTML Features of the Master Page Accessibility Features of the Master Page
Introduction Web standards enable you to build Web sites that are accessible to the broadest possible audience with the least amount of work. The promise of Web standards is that you can design a page once and have the page appear and function in exactly the same way in any modern browser. For example, when built against standards, a page that was designed to display a certain way in Microsoft Internet Explorer can appear the same way in other browsers, such as Mozilla Firefox, Netscape Navigator, Opera, Camino, and Safari, without requiring you to perform any additional work. An additional benefit of Web standards is that they make your Web sites more easily accessible to persons with disabilities. This is a broad audience that includes everyone from a middle-aged person with failing eyesight, to a person who just broke his or her arm while skiing, to a person who is completely blind. Standards prevent you from unintentionally blocking persons with temporary or permanent disabilities from your Web pages. The Microsoft ASP.NET 2.0 framework was designed to be the best framework for building Web sites that meet public Web standards. In particular, every control in the ASP.NET 2.0 framework was extensively reviewed and tested against both XHTML and accessibility standards. Furthermore, Microsoft Visual Studio 2005 includes new tools for validating your Web pages against both XHTML and accessibility standards. The purpose of this paper is to provide you with an overview of XHTML and accessibility standards, and explain how you can take advantage of ASP.NET 2.0 and Visual Studio 2005 to meet these standards. At the end of this paper, you are provided with a step-by-step walkthrough for creating an ASP.NET 2.0 Web site that satisfies both XHTML and accessibility standards.
Building XHTML Web Sites HTML is officially outdated. The World Wide Web Consortium (W3C) published the first version of XHTML as a recommendation on January 26, 2000. The XHTML standard is intended as a replacement for HTML. According to the W3C, "XHTML is the successor of HTML" (http://www.w3.org/MarkUp/). The framers of the XHTML standard have two broad goals: • •
Create a cleaner separation between document structure and presentation. Reformulate HTML as an application of XML.
In pursuit of the first goal, the W3C has been steadily removing purely presentational elements and attributes from HTML (a process that they started with HTML 4.0). For example, XHTML 1.0 Strict does not include elements such as the tag, or attributes such as the bgcolor attribute, because these elements and attributes are used
solely to describe the appearance of a document, and they have nothing to do with a document's structure. The W3C has been attempting to wean Web site designers and developers away from the idea that any particular tag should have any particular appearance. For example, you might think that the purpose of an tag (the heading tag) is to render large, bold text in a page. That would be wrong. The tag is used to mark a heading in a document, and nothing else. It is up to the browser to determine how the heading tag should be rendered. A screen reader used by a person with reduced eyesight might read aloud the contents of a heading tag with a booming, authoritative voice. A PDA, which doesn't support multiple font sizes, might render the contents of a heading tag with blinking text. You should not attempt to use page elements, such as the tag, to control the appearance of a Web page. Instead, you should indicate the appearance of a Web page through the use of Cascading Style Sheets. Preferably, the Cascading Style Sheets should be external Cascading Style Sheets. Use tags and attributes to mark up the structure of a document, and use Style Sheets to control the document's presentation. The second goal of XHTML is to enforce the stricter rules of XML on HTML developers. In the words of the W3C, "XHTML 1.0 is a reformulation of HTML 4.01 as an XML 1.0 application" (http://www.w3.org/MarkUp/). In other words, when you build a Web page using XHTML, you are actually creating an XML document. An XML document has a much stricter syntax than an HTML document. For example, XML is case-sensitive, all XML attributes must be quoted, and XML tags cannot overlap. Forcing Web site developers and designers to follow the rules of a more demanding language has many benefits. One benefit is that pages written with XHTML markup are more cross-browser, crossdevice, and cross-operating system compatible. If you open a traditional HTML page in a browser, the browser will make every effort to render the page. The browser will attempt to render the page even if your HTML is a total mess. For example, Internet Explorer (and Firefox and Opera) will display the following HTML page just fine. this is bold and italic and this is bold