I'm confused about when to use server controls and HTML controls on my Web form. Can you explain?
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 (https://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.
Dig Deeper on Win Development Resources
Related Q&A from Daniel Cazzulino
Here Daniel Cazzulino explains how to load a DSL (domain specific language) domain model instance file programmatically. This requires the .NET type ... Continue Reading
Here we offer a glimpse at 12 of .NET development expert Danny Cazzulino's top ASP.NET questions and answers. Continue Reading
C# developers should NOT be modifying InitializeComponent method in the code-behind (or any of the variable definitions) by hand. Continue Reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.