10

Are there any good methods for getting ASP.NET 2.0 to validate under the XHTML 1.0 Strict (or Transitional) DTD? I'm interested to hear some ideas before I hack up the core of the HTTP response.

One major problem 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 fundamental to ASP.NET, as you all know. Hmmmm.

Calroth
  • 128
  • 1
  • 7
craigmoliver
  • 6,499
  • 12
  • 49
  • 90

3 Answers3

11

ASP.NET 2.0 and above can indeed output Strict (or Transitional) XHTML. This will resolve your 'there is no attribute "name"' validation error, amongst other things. To set this up, update your Web.config file with something like:

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

For Transitional XHTML, use mode="Transitional" instead.

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

Calroth
  • 128
  • 1
  • 7
  • I'm not sure what I'm doing wrong, but it doesn't seem to do anything. I'm using .Net 3.5, and I set this configuration tag to all the possible values, and my meta tags still render with a closing . Anything I could do? – Allov Jul 06 '11 at 14:12
4

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
  • 25,869
  • 4
  • 37
  • 58
  • Beta is a little to risky for a production app for me (not for StackOverflow). Besides, the app has already been written. – craigmoliver Sep 30 '08 at 23:36
  • 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. –  Oct 01 '08 at 00:39
  • ASP.NET MVC 1.0 was released 2009-03-17. Work is currently on a 2.0 version. – foson Aug 05 '09 at 19:28
2

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
  • 29,592
  • 16
  • 81
  • 103
  • 1
    The Reapter control is aweful, span or tables is all you get, look at the ListView in 3.5 instead. – craigmoliver Sep 30 '08 at 23:25
  • 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 Oct 01 '08 at 00:01
  • Perhaps you're using it differently than me but I never had any problems with the markup, because it doesn't generate any! – roryf Oct 01 '08 at 08:48