Digital Colony!

W3C Validation for ASP.NET Data Controls

If you've had the W3C Validator curse your ASP.NET 2.0 code for not being XHTML, it may not be your fault. The ASP.NET engines sees the W3C validator as down-level browser and renders non-XHTML compliant code. Your code is most likely fine. The problem is with ASP.NET.

Getting ASP.NET to Play Nice with the W3C

1- Select ADD New Item to your Project or Website.
2- At the bottom of the list of choices is a Browser file. Select that and name it W3C.browser.
3- Visual Studio will ask if it can create an App_Browsers folder. Give your blessing and proceed.
3- Visit iDunno.org and copy the .browser text linked from that post and paste it onto your newly created W3C.browser file.
4- Upload the new folder and file.
5- Now retest with the W3C.

Your page should now validate. If it fails, it is most likely your fault and no longer the fault of the ASP.NET engine.

Labels: , ,

 

Add META keywords and Description in ASP.NET

Here is the syntax for programmatically adding META tags to an ASP.NET 2.0 page.
HtmlMeta metaDesc = new HtmlMeta();
metaDesc.Name = "description";
metaDesc.Content = "Tips on roasting coffee at home";
Page.Header.Controls.Add(metaDesc);

HtmlMeta metaKey = new HtmlMeta();
metaKey.Name = "keywords";
metaKey.Content = "roast, coffee, home, tips";
Page.Header.Controls.Add(metaKey);
ASP.NET will render the above code to valid XHTML META tags.
<meta name="description" content="Tips on roasting coffee at home" />
<meta name="keywords" content="roast, coffee, home, tips" />

Labels: , ,

 

Converting HTML to XHTML Programmatically in .NET

The Pro Version of FreeTextBox has a neat feature that will clean up poorly written HTML to a cleaner XHTML.
FreeTextBoxControls.FreeTextBox ftb = new FreeTextBoxControls.FreeTextBox();
string html = "<P><img src=joe.gif width=200 height=100 vspace=10>";
ftb.Text = html;
string xhtml = ftb.Xhtml;

Trace.Write("HTML", html);
Trace.Write("XHTML", xhtml);

Before and After

<P><img src=joe.gif width=200 height=100 vspace=10>
<p>
<img src="joe.gif" width="200" height="100" vspace="10" />
</p>
The FreeTextBox closed the paragraph tag, made the paragraph tag lower-case, added quotes to all the attributes and closed the img tag to make the entire string XML compliant. What this control didn't do was replace the deprecated vspace attribute with it's CSS equivalent.

Labels: , , ,

 

Digital Colony Copyright © 1999-2008 XHTML   508
This site uses Blogger, which is not 100% XHTML compliant.
Try...Catch Disclaimer: For brevity many examples do not include error handling. That is your responsibility.