Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm working on my first ASP.NET project and I'm torn between using asp tags (<asp:SomeElement) everywhere or use some regular HTML for simple things that need no code behind, like fixed divs, static text, etc.

I think it would be best to use ASP tags only for code behind and other dynamic stuff, whereas static elements can be in vanilla HTML, but that's assuming I won't ever need to turn them into ASP.NET in the future. Is there a best practice/recommended approach for this?

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

Personally I'd say use HTML controls whenever possible. It makes it much easier to compare your source to the rendered markup, which is nice when you're building CSS and javascript, or when you're troubleshooting rendering issues.

If down the road you need to convert one to a server control, it's really not that bad. In some cases you can just throw a runat="server" on it, and have access to a lot of properties from the code-behind, or you can change the tag as needed (<input> to <asp:TextBox>, etc.) in just a few seconds.

share|improve this answer
    
I'm with Joe. Use ASP controls when you must, use HTML when you can. –  Eric King Aug 9 '13 at 5:11
add comment

Microsoft first introduced server controls in an attempt to make web development seem as much like VB6 windows development as possible. It enabled developers who had very little knowledge of HTML and the web, to build web pages by dragging controls onto a design surface.

In the early days of .NET, this (arguably) made a lot of sense, but as the web has matured, and developers in general are more knowledgeable and comfortable with rolling their own HTML, the server control model seems stale, and developments like MVC come along which align more closely with the way web devs are used to working nowadays.

That said, if you are comfortable putting the HTML directly into the page, then go for it. You have more control over the page's rendering, and as Joe stated it's much easier to troubleshoot layout issues.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.