
Understanding the Role of HTML and XHTML
HTML is the markup used to render information in a client side Web browser. HTML is a text-based markup
with numerous elements that describe forms, user input controls, formatted text, images, tables and more.
Pure HTML is not case sensitive. Thus, <FORM>, <FoRm>, <Form> and <form> are all legal HTML and
are treated identically.
Many programmers dislike writing raw HTML. Luckily, ASP.NET provides Web controls that are
automatically rendered as HTML when sent to the requesting Web browser. This is not to say ASP.NET
developers never have to author HTML manually. Rather, HTML is automatically created on the developer’s
behalf.
The core elements of an HTML document consist of <html>, <head>, <body> and <form> :
• <html> </html> used to open and close the definition of an HTML document.
• <head> </head> (optional) used to define the title of the document that is displayed in the Web
browser’s title bar. Can also contain metadata.
• <body> </body> used to mark the scope of the document’s contents.
• <form> </form> used to define HTML form(s). Acts as a container of HTML Web controls.
Consider the following HTML file, default.html. By default, HTML files take an *.htm or *.html file name
extension:
<html>
<body>
<form>
<input type="text" name="numb1" />
+
<input type="text" name="numb2" />
<input type="submit" value=" = " />
</form>
</body>
</html>
Note the elements and attributes used in the HMTL document above. Elements are the opening and closing
“tags” used with the HTML. For example: <body>, <input … />, </html>. Attributes are the name/value
Here is the HTML rendered in Internet Explorer (IE) 7.
By default, Visual Studio 2008 makes use of a more structured flavor of HTML called XHTML. XHTML is
a formal specification submitted to W3C, an internet standards body (see http://www.w3.org/1999/xhtml for
full details). Although XHTML does not add any additional functionality beyond HTML 4.01, it does
provide some much needed structure to basic HTML by providing validation rules. XHTML is in fact,
considered a valid XML document! This makes is much easier to read them and programmatically manipulate
them. The general consensus is that XHTML will eventually replace HTML.
The DOCTYPE declaration at the top of the file points to a Document Type Definition (DTD) schema file,
which specifies the version of XHTML that this Web page conforms to. This information is used by the Web
browser to correctly render the HTML.
Consider the following mark up for an ASP.NET Web page.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
The ASP.NET Web controls automatically produce XHTML-compliant markup. However, when authoring
the markup by hand, you must ensure. All elements and attributes must be lower case (<html>, not <Html>
or <HTML>). All elements must have a proper closing element (believe it or not, pure HTML does not
demand this). A value assigned to an attribute must be placed in quotation marks. For example runat="server"
not runat=server or runat=‘server’. The “id” attribute is always used to define an identifier for every control -
never “name”.
If you manually author some ill formed HTML markup, VS 2008 will generate validation errors. Be aware
that in most cases, these ‘errors’ are recognized at design time only, and will not affect the processing of your
page. Even with markup errors, your Web program will still compile and render properly in most Web
browsers.
For example, the following markup generates a validation error as we have closed the <html> opening tag with
a </HTML> closing tag. Note the location of the cursor and the Tooltip error message below.
Although most ASP.NET Web applications benefit greatly by using XHTML, the type of HTML validation
used by Visual Studio can be configured via the Tools | Options dialog box. From here, open the Text Editor |
HTML | Validation node on the left side. Select a validation target from the drop-down list box on the right
side.
HTML and XHTML
Table of Contents
Copyright (c) 2008. Intertech, Inc. All Rights Reserved. This information is to be used exclusively as an
online learning aid. Any attempts to copy, reproduce, or use for training is strictly prohibited.
Courseware
Training Resources
Tutorials
Services