views:

132

answers:

7

I'm struggling with a few in-house developers that are creating some web apps in VS 2008 using C#.

It appears that the native tools and components in VS 2008 are not being nice about creating Web Standard code.

For example, the navigation component creates items in its own table structure.

Is there anyway to make a web project from Visual Studio create nice, clean, browser friendly code?

+1  A: 

Certainly. If a component doesn't produce markup you like, then you don't use it. It's just that simple.

Having said that, be sure to check out Visual Studio 2010 beta 1 to see if your issues have been addressed. If they haven't, then you get to complain about them in a way that might get them fixed.

John Saunders
+1  A: 

VS 2008 web projects don't do anything web-standards-unfriendly. The standard ASP.NET controls (like the menu control you mentioned)? That's another story -- some use a mess of tables and javascript to do their thing.

The good news? You can use what you want of ASP.NET without having to use those controls if you don't want to.

Jonathan
A: 

The Web Projects themselves are simply containers for the code that you create and a mechanism for managing and building the compiled project.

Based on my experience, the controls generated by VS comply to web standards ... that being said, browsers differ on which standards they do or do not enforce and how they enforce them. For the most part, you have a high level of control of the HTML that is output from your page. The table structure generted by the navigation control id valid HTML - you may be wanting to avoid the use of tables in which case, that particular control might not be for you.

For the most part, when you have a complex control you will need to take what you get - the HTML that is generated may not be intuitive to you and your team but that is often the price paid for the time savings gained by using a pre-built control, particularly one that is intended to service the needs of a wide variety of uses. (The same can be said for most code/script libraries you use/buy/find)

Many controls offer templating that provides you with the ability to define a template for how the resultant HTML is generated.

James Conigliaro
A: 

If you want cleaner markup, you have a few options:

a) Check out the CSS Friendly control adapters from codeplex. They help alot with certain controls. b) Avoid the more complex server controls. There is very little one can't do nearly as effectively with a repeater and some user controls that one can't do with most any databound control for instance. c) Try ASP.NET MVC. No neato server controls to do UI lifting, but it will let you make very, very clean UIs.

Wyatt Barnett
+2  A: 

You can use CSS Friendly Control Adapters to alter the output of the current ASP.NET controls. It's easy to set up and you don't have to change any existing source code.

If you're bound to ASP.NET WinForms, you could create you own set of controls or use 3rd party controls. There is also a XHTML configuration setting you could set to Strict, so that the controls try to render more valid core.

When you really want to write nice, clean, browser friendly code, you could take a look at ASP.NET MVC. ASP.NET MVC gives you complete control of the output, but that means you have to do all the things WinForms currently does for you, yourself...

Ronald
+1  A: 

Go MVC !!! you will have complete controle over your UI

Yassir
+1  A: 

My two cents: machine-generated code is almost never as standards-compliant as the code I write by hand, especially when you get into fancy widgets and whatnot. The obvious trade off is that writing code by hand can be tedious and time-consuming.

We've come a long ways since the dark ages of code-junk that frontpage or dreamweaver used to spit out, but even still...

In the end, your code is only ever as good as your programmers.

Gabriel Hurley