4.1. Introduction to Server Controls
It's important to understand how server controls operate and how they are completely different from the way you define controls in other languages like ASP or PHP, another popular programming language to create dynamic web sites.
For example, to influence the text in a text box in these languages, you would use plain HTML and mix it with server-side code. This works similar to the example in Chapter 2 where the current date and time are displayed on the page. For example, to create a text box with a message and the current time in it in classic ASP, you can use the following code:
<input type="text" value="Hello World, the time is now <%=Time()%>" />
As you can see, this code contains plain HTML, mixed with a server-side block, delimited by <% and %> that outputs the current time using the equals (=) symbol. This type of coding has a major disadvantage: the HTML and server-side code is mixed, making it difficult to write and manage your pages. Although this is a trivial example where it's still easy to understand the code, this type of programming can quickly result in very messy and complex pages.
Server controls work differently. In ASP.NET, the controls "live" on the server inside an ASPX page. When the page is requested in the browser, the server-side controls are processed by the ASP.NET runtime — the engine that is responsible for receiving and processing requests for ASPX pages. The controls then emit client-side HTML code that is appended ...
Get Beginning ASP.NET 3.5: In C# and VB now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.