In this chapter
ASP.NET comes with a suite of server controls. These aren't COM+ components ; they're controls that are kicked off when a page request is made. They run on the server and generate HTML code that's inserted into the outgoing HTML stream. The browser sees them as HTML, whereas the ASP.NET page and developer see them as controls.
The question of browser compatibility probably has already entered your mind. Don't worry, though; the HTML code the server controls produce is compatible with any browser. And for some of the rich server controls, such as the Calendar and TreeView , this is a great advantage. Creating cross-browser versions of them would take a sizeable effort. You get them free of charge with ASP.NET.
ASP.NET server controls fall into four categories: Intrinsic controls, List controls, Rich controls, and Validation controls. This chapter has sections that describe each control category and provide examples.
You can add server controls to your ASP.NET page in two ways: You can type in the code, or you can drag a control from the Toolbox while Visual Studio is in Design mode. The biggest differences between using the ASP.NET server controls and just adding straight HTML code is that the controls need a runat ="server" directive and their names differ from their HTML counterparts: They all have an asp: prefix.
The following code shows how to add an ASP.NET TextBox server control to the code:
<asp:TextBox runat="server" id="Example1" Text="Some text here..." MaxLength="30" />
You can see the same TextBox control in Design mode within the Visual Studio editor in Figure 6.1. It's being designed visually with the Property window.
Figure 6.1. This TextBox control is easily edited in the Properties window.