Articles → .NET → ASP.NET XHTML Compliance

ASP.NET XHTML Compliance







  1. All elements either include an explicit closing tag or are self-closing




  2. <!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>
    	<title> </title>
    </head>
    
    <body>
    	<form name="form1" method="post" action="Default.aspx" id="form1">
    		<div>
    			<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2MTY2ODcyMjlkZNLaISFnJOBvA0oQ9ZjtvoTDUaMl" /> </div>
    	</form>
    </body>
    
    </html>


  3. Tag and attribute names are rendered in lowercase, and attribute values are included in double quotation marks.
  4. Formatting information is rendered using only cascading style sheet styles.


  5. <font color="red">hi</font>






    <asp:GridView ID="gvRuleThree" runat="server" HeaderStyle-BackColor="Red"> </asp:GridView>




    DataSet ds = new DataSet();
    ds.ReadXml(Server.MapPath("rule_3.xml"));
    gvRuleThree.DataSource = ds.Tables[0];
    gvRuleThree.DataBind();




    <?xml version="1.0" encoding="utf-8" ?>
    <root>
      <child>child1</child>
      <child>child2</child>
      <child>child3</child>
      <child>child4</child>
    </root>




    <!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>
    	<title> </title>
    </head>
    
    <body>
    	<form name="form1" method="post" action="Default.aspx" id="form1">
    		<div>
    			<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE4MDE3NTcxODcPZBYCAgMPZBYCAgEPPCsADQIADxYEHgtfIURhdGFCb3VuZGceC18hSXRlbUNvdW50AgRkDBQrAAEWCB4ETmFtZQUKY2hpbGRfVGV4dB4KSXNSZWFkT25seWgeBFR5cGUZKwIeCURhdGFGaWVsZAUKY2hpbGRfVGV4dBYCZg9kFgoCAQ9kFgJmDw8WAh4EVGV4dAUGY2hpbGQxZGQCAg9kFgJmDw8WAh8GBQZjaGlsZDJkZAIDD2QWAmYPDxYCHwYFBmNoaWxkM2RkAgQPZBYCZg8PFgIfBgUGY2hpbGQ0ZGQCBQ8PFgIeB1Zpc2libGVoZGQYAQULZ3ZSdWxlVGhyZWUPPCsACgEIAgFkyryzGmoNlkjGPgqOgUEngSbk1/c=" /> </div>
    		<div>
    			<table cellspacing="0" rules="all" border="1" id="gvRuleThree" style="border-collapse:collapse;">
    				<tr style="background-color:Red;">
    					<th scope="col">child_Text</th>
    				</tr>
    				<tr>
    					<td>child1</td>
    				</tr>
    				<tr>
    					<td>child2</td>
    				</tr>
    				<tr>
    					<td>child3</td>
    				</tr>
    				<tr>
    					<td>child4</td>
    				</tr>
    			</table>
    		</div>
    	</form>
    </body>
    
    </html>


  6. In ASP.NET, if controls generate IDs, as occurs in the Repeater, GridView, and other controls the format of the IDs match XHTML 1.0 Transitional guidelines.


  7. <asp:GridView ID="gvRuleThree" runat="server" HeaderStyle-BackColor="Red">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:TextBox runat="server"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>




    Picture showing the gridview with a textbox and a label

    Click to Enlarge



    <!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>
    	<title> </title>
    </head>
    
    <body>
    	<form name="form1" method="post" action="default.aspx" id="form1">
    		<div>
    			<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTkyOTE3NzczMw9kFgICAw9kFgICAQ88KwANAgAPFgQeC18hRGF0YUJvdW5kZx4LXyFJdGVtQ291bnQCBGQMFCsAARYIHgROYW1lBQpjaGlsZF9UZXh0HgpJc1JlYWRPbmx5aB4EVHlwZRkrAh4JRGF0YUZpZWxkBQpjaGlsZF9UZXh0FgJmD2QWCgIBD2QWAgIBDw8WAh4EVGV4dAUGY2hpbGQxZGQCAg9kFgICAQ8PFgIfBgUGY2hpbGQyZGQCAw9kFgICAQ8PFgIfBgUGY2hpbGQzZGQCBA9kFgICAQ8PFgIfBgUGY2hpbGQ0ZGQCBQ8PFgIeB1Zpc2libGVoZGQYAQULZ3ZSdWxlVGhyZWUPPCsACgEIAgFkZUDE/Ou3onhLafNN/QCNRfW25LU=" /> </div>
    		<div>
    			<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBQK01eLgDQKOhc2fBQKthc2fBQLEh82fBQLjhc2fBX21d0EgZwVtkdBaWgYezHSZwHS/" /> </div>
    		<div>
    			<table cellspacing="0" rules="all" border="1" id="gvRuleThree" style="border-collapse:collapse;">
    				<tr style="background-color:Red;">
    					<th scope="col"> </th>
    					<th scope="col">child_Text</th>
    				</tr>
    				<tr>
    					<td>
    						<input name="gvRuleThree$ctl02$ctl00" type="text" /> </td>
    					<td>child1</td>
    				</tr>
    				<tr>
    					<td>
    						<input name="gvRuleThree$ctl03$ctl00" type="text" /> </td>
    					<td>child2</td>
    				</tr>
    				<tr>
    					<td>
    						<input name="gvRuleThree$ctl04$ctl00" type="text" /> </td>
    					<td>child3</td>
    				</tr>
    				<tr>
    					<td>
    						<input name="gvRuleThree$ctl05$ctl00" type="text" /> </td>
    					<td>child4</td>
    				</tr>
    			</table>
    		</div>
    	</form>
    </body>
    
    </html>




  8. form elements include a name attribute
  9. XHTML requires all elements to be enclosed in a container element. such as input elements, are rendered in div elements.


  10. <asp:TextBox ID="txtName" runat="server"></asp:TextBox>




    <!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>
    	<title> </title>
    </head>
    
    <body>
    	<form name="form1" method="post" action="Default.aspx" id="form1">
    		<div>
    			<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE3NDI1ODEyMjhkZPf5p4ff8FsM3OEQHCM0SkoFkL79" /> </div>
    		<div>
    			<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgKiwteNAgLEhISFCzdSkT4DBV3uYEShorRdOkj0h+82" /> </div>
    		<input name="txtName" type="text" id="txtName" /> </form>
    </body>
    
    </html>


  11. ASP.NET encodes characters, such as & (for example, as & amp;).


  12. <asp:TextBox ID="txtName" runat="server" Text="&"></asp:TextBox>




    <input name="txtName" type="text" value="&" id="txtName" />


  13. Any script elements that are rendered into the page use the appropriate type attribute (for example, type="type/javascript") and do not include language attribute.
  14. If ASP.NET renders script blocks, the content of the script blocks is rendered inside an XML (HTML) comment.


<!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>
	<title> </title>
</head>

<body>
	<form name="form1" method="post" action="Default.aspx" id="form1">
		<div>
			<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
			<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
			<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJMzcxMjI5NDM1ZGSwm9MkcTa26p8riSo14DoQtkA4eA==" /> </div>
		<script type="text/javascript">
		//<![CDATA[ 
		var theForm = document.forms['form1'];
		if(!theForm) {
			theForm = document.form1;
		}

		function __doPostBack(eventTarget, eventArgument) {
			if(!theForm.onsubmit || (theForm.onsubmit() != false)) {
				theForm.__EVENTTARGET.value = eventTarget;
				theForm.__EVENTARGUMENT.value = eventArgument;
				theForm.submit();
			}
		}
		//]] >
		</script>
		<div>
			<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwKgxKq3DgLEhISFCwKSw44DkvTmJl2cpA0Ugu4P+7MfthbHkU0=" /> </div>
		<input name="txtName" type="text" value="&" id="txtName" /> <a id="lnkTest" href="javascript:__doPostBack('lnkTest','')">Test</a> </form>
</body>

</html>





Conclusion





Posted By  -  Karan Gupta
 
Posted On  -  Thursday, December 8, 2011

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250