问题
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.
回答1:
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.
回答2:
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.
回答3:
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.
来源:https://stackoverflow.com/questions/155532/xhtml-1-0-strict-or-transitional-compliance-in-asp-net-2-0-3-5