views:

1491

answers:

3

Are there any good methods for getting ASP.NET to valid under the XHTML strict DTD? I'm interested to hear some ideas before I hack up the core of the HTTP response.

One major problem of the major problems is the form tag itself, this is the output I got from W3C when I tried to validate:

Line 13, Column 11: there is no attribute "name".
<form name="aspnetForm" method="post" action="Default.aspx" onsubmit="javascript

That tag is very fundimental to ASP.NET, as you all know. Hmmmm.

+2  A: 

Its possible to change the output of ASP.NET controls using techniques like the CSS Adapters. Although I wouldn't personally recommend you use these out of the box, it might give you some hints on a good solution.

I generally avoid using the ASP.NET controls where ever possible, except ones that don't generate markup on their own such as the Repeater control. I would look into the ASP.NET MVC framework (what StackOverflow is built on) as this gives you 100% control over markup.

roryf
The Reapter control is aweful, span or tables is all you get, look at the ListView in 3.5 instead.
craigmoliver
I've no experience with 3.5 so couldn't comment on ListView but I don't see the problem with the Repeater control, you can use whatever tags you choose and have several 'sub-controls' to generate your own markup as well.
roryf
check out the source
craigmoliver
Perhaps you're using it differently than me but I never had any problems with the markup, because it doesn't generate any!
roryf
+4  A: 

Have you considered the ASP.NET MVC Framework? It's likely to be a better bet if strict XHTML compliance is a requirement. You gain more control of your output, but you'll be treading unfamiliar territory if you're already comfortable with the traditional ASP.NET model.

Gabriel Isenberg
Beta is a little to risky for a production app for me (not for StackOverflow). Besides, the app has already been written.
craigmoliver
web controls aren't built for xhtml validation. They're built for convenience. Either use CSS addapters or rewrite your UI. Its a sticky pill, but its best taken with lots of alcohol.
Will
ASP.NET MVC 1.0 was released 2009-03-17. Work is currently on a 2.0 version.
foson
+9  A: 

ASP.NET 2.0 can indeed output strict XHTML. This will take care of your 'there is no attribute "name"' validation error, amongst other things. To set this up, you need to update your Web.config file with something like:

<system.web>
    ... other configuration goes here ...
    <xhtmlConformance mode="Strict" />
</system.web>

See How to: Configure XHTML Rendering in ASP.NET Web Sites on MSDN.

Calroth