When to use server controls and HTML controls on a Web form

When to use server controls and HTML controls on a Web form

I'm confused about when to use server controls and HTML controls on my Web form. Can you explain?

    Requires Free Membership to View

    When you register, you'll begin receiving targeted emails from my team of award-winning writers. Our goal is to provide a unique online resource for developers, architects and development managers tasked with building and maintaining enterprise applications using Visual Basic, C# and the Microsoft .NET platform.

    Hannah Smalltree, Editorial Director

    By submitting your registration information to SearchWinDevelopment.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchWinDevelopment.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

HTML controls have a 1-1 mapping with the HTML tags. Their programming model is just like plain HTML, as well as its properties, which are exactly those documented in the W3C specification for HTML (http://www.w3.org/TR/html4).

In order to set values and modify these controls from .NET code (server-side), you need to right-click on them and select Run As Server Control, which introduces us to the server control concept. A server control is one that is run by ASP.NET, and available to .NET code in the code-behind or runat="server" script sections. Non-server controls (HTML) are not processed by ASP.NET. Rather, they are just design-time "views" of the underlying HTML source of the page itself.

Server controls can be either HTML Server Controls or Web Forms Controls (a.k.a. WebControls). The difference between the two is about functionality and design-time support. The latter have better designers, a more intuitive programming model, more OOP, can control their own rendering logic to better target the client platform, etc. So, if you need to access a control from .NET code, I'd say you should use WebControls. On the other hand, if you don't need to change a label text, a table configuration, etc., go for the the (non-server) HTML controls, which render faster and don't consume resources on the server for processing.

This was first published in November 2003