Extreme ASP.NET Makeover: Style - W3C XHTML Validation

Play Extreme ASP.NET Makeover: Style - W3C XHTML Validation
Sign in to queue


Embracing the Web

ASP.NET Web Forms goes out of its way to protect you from the big, bad old Web. A world of HTML, CSS, and JavaScript all served up over HTTP. A world where state is ephemeral and statelessness is a way of life. In the extreme, ASP.NET Web Forms gives you a drag-and-drop experience where you never have to look at an angle bracket. Where an illusion of statefulness is provided by SessionState and ViewState. Rob Conery said it best when he described ASP.NET Web Forms as an "abstraction wrapped in deception covered in lie sauce presented on a plate full of diversion and sleight of hand." For simple applications, this strategy can work well as you don't have to worry about the idiosyncrasies of the Web. To harness the true power of the browser, you do need to embrace the Web and the fundamental technologies that comprise it - HTML, CSS, JavaScript, and HTTP.

The Web can be a scary place, especially if you've ever dared to look at the HTML source for a typical Web page of the ASP.NET variety. The HTML source is awash in hidden inputs, crazy identifiers, cryptic JavaScript, and HTML that looks like it's been through a blender. This is the price of ASP.NET Web Forms trying to hide the stateless nature of the Web from you.

If however you embrace fundamental Web technologies, you can have clean, readable HTML styled with CSS and dynamic behaviours provided by understandable JavaScript.  You don't even have to abandon ASP.NET Web Forms to do it. (In many ways, ASP.NET MVC makes it easier to embrace these Web technologies, but that's the topic of a later article.) You can bring the power of the Web to your ASP.NET Web Forms applications!

Living in a (X)HTML World

The world of the Web is built around HTML in one form or another. Although ASP.NET Web Forms tries to protect you from the angle brackets, chances are better than not that you've spent some time looking at raw HTML. If you haven't, I would recommend devoting some time to the free introductory tutorials at w3schools.com.

Depending on your Web application, cross-browser compatibility may or may not be a concern for you. Internal enterprise applications typically only require that they run on the corporate standard browser, which is most often Microsoft Internet Explorer. At the other extreme are public Web sites that want to target the broadest audience and therefore be compatible with the broadest range of available browsers.

If you're building a public Internet site, you probably want to know which browsers are currently popular so that you can ensure that your site works properly in them. Many companies offer browser usage statistics - often for free - which can serve as a guide to currently popular browsers. As shown below, Microsoft Internet Explorer is still the dominant browser, but Firefox makes up a substantial piece of the market. So compatibility with the major versions of those two browsers is a must for any public Internet site.

Generic Episode Image
Browser Version Market Share for April 2009 - source Net Applications

Always take browser usage statistics with a large grain of salt, because they are highly dependent on the site's target demographic. For consumer sites, the above graph is roughly representative of current browser usage as it incorporates data from a wide range of popular sites. Technical sites, such as my blog, tend to have a much higher percentage of alternative browsers, such as Firefox, Chrome, and Opera. I would expect Apple-related sites to have a much higher percentage of visits from Safari users as that is the default browser on OSX. So when deciding which browsers and operating systems to test your Web application on, you need to consider its target audience.

There are some easy things that you can do to increase the likelihood that your Web application will work across browsers. Modern browsers are designed to render HTML 4.01 and XHTML 1.0/1.1, but they do provide backward compatibility with previous HTML specifications. Browsers are typically very forgiving in their parsing of HTML and browser incompatibilities are often manifestations of the rules that a particular browser uses to parse bad HTML. For example, the following is invalid HTML and XHTML:

<p><em>The quick brown dog jumped over the lazy fox.</p></em>

Notice how the <p> and <em> overlap. Neither tag contains the other. This is invalid HTML and XHTML. Your chances of cross-browser compatibility are dramatically improved if your markup is valid HTML 4.01 or XHTML 1.0/1.1. "Valid" means that the document markup conforms to the relevant W3C specification. You can check the validity of your HTML/XHTML document using the free W3C Markup Validation Service.

Other videos from this article

· W3C XHTML Validation

· Visual Studio Validation

· Comparing HTML and XHTML

· XHTML Strict

· CSS Zen Garden

Read the full article at https://msdn.microsoft.com/en-us/magazine/dd894045.aspx



Download this episode

The Discussion

Add Your 2 Cents