views:

63

answers:

4

I understand that it may not be possible to decouple the client-side from the server-side code in ASP.NET Webforms. What steps can be taken to produce a website on this framework that complies to web standards?

I am particularly concerned with making the site accessible with JavaScript disabled, and compliant to WCAG2 at conformance level AA.

Is it possible to achieve a separation between content (HTML), presentation (CSS), and behaviour (JavaScript)?

+2  A: 

It's possible, but it's not that easy in ASP.Net WebForms:

  1. Newer ASP.Net versions are more standard-compliant than old ones. So, use the newest ASP.Net version possible. ASP.Net 4 has some nice features to make HTML markup cleaner (see blog post for details)
  2. If you're still not happy with the code, generated by some of the standard controls, look for their third-party equivalents. There are good chances that you'll find open-source or commercial controls, generating much cleaner code than default ones.
  3. If you're still not happy with some of the third-party controls, write your custom controls and fill them with nice clean standard-compliant code.
buru
A: 

If you are not really hell bent on ASP.NET, you could also give a try on ASP.NET MVC. MVC has many similarities to ASP.NET. But the best part is you have full control over the HTML output that is rendered to the browser.

If you don't have an option of choosing MVC, and you are not happy with the default output of the ASP.NET server control, you can ovveride the Render method of the ASP.NET server control. Please refer to Rendering an ASP.NET Server Control.

You can also override the output of the child controls if its a composite control like DataGrid.

Hope this helps.

Nilesh Gule
@Nilesh: was there a reason you posted a .NET 1.1 link?
John Saunders
@John, I didn't have any specific reason. I just wanted to show a link which demonstrated how it can be done.
Nilesh Gule
@Nilesh: that's fine, but if you post a .NET 1.1 link, the reader will follow it to more .NET 1.1 links, which lead to more .NET 1.1 links - the reader will be stuck in a maze of documentation from 2003.
John Saunders
A: 

You can inherit and override the Render method, but for more complex controls you're probably not going to want to put in the time when better alternatives exist.

Michael Mac McCann
+1  A: 

If MVC or .NET4 aren't options, take a look at the CSS-Friendly Control Adapters.

http://cssfriendly.codeplex.com/

kbrimington