Using either technique, the resulting web page should look something like that shown in Fig.34. This page will demonstrate some of the properties, events, and methods common to all ASP.NET server controls.
Fig.34 ASP.NET server controls: Basics

To create this web page without benefit of VS2005, open Notepad or your favorite editor capable of creating a flat text file (not Microsoft Word, for example, unless you want to jump through hoops). Enter the code in below example into the file.
Example. ASPNETServerControlBasics-TextEditor.aspx

Save the file as ASPNETServerControlBasics-TextEditor.aspx in any folder you want, say c:\websites.
To easily see your page processed by ASP.NET on a web server, you need to access the page in a browser via localhost . You must create a virtual directory for the folder that contains the web page file.
Open Computer Management by right-clicking My Computer and selecting Manage from the menu. (Alternatively, open Start->Control Panel->Administrative Tools->Computer Management.) Drill down to Services and Applications Internet Information Services Web Sites->Default Web Site and right-click on Default Web Site. From the drop-down, select New->Virtual Directory. Follow the wizard, using websites for the alias and browsing to the folder location where you put the .aspx file.
Now open a browser and give it the following URL:
http://localhost/websites/ASPNETServerControlBasics-TextEditor.aspx
The browser will cook a moment while the ASP.NET runtime processes the page and returns the rendered HTML.
Now you'll create the exact equivalent web page using VS2005. Open the IDE and create a new web site called ASPNETServerControlBasics. Enter a few HTML header elements and drag and drop a Label control onto the page so that the finished default.aspx file looks something like the code shown in below Example. Notice how the combination of drag and drop and Intellisense makes for so much less tedious and error-prone typing.
Example. Content of Default.aspx in ASPNETServerControlBasics

Once the controls are in place, you now want to create an event handler for the Init event of the label control lblTime. Switch to Design view if you are not there. Select the label lblTime. The lightning bolt icon will appear along the top of the Properties window.
Clicking on the lightning bolt will display all the possible events for this control. Double-click on the cell next to the Init event. The code-behind file, default.aspx.cs, will open on the work surface with a code skeleton in place for the event handler, named lblTime_Init, and the cursor inside the curly braces, ready for you to start typing your C# code. Enter the highlighted code from below Example .
From ASPX to Drag and Drop
When you develop with VS2005, the goal is to use Intellisense and drag and drop as much as possible, rather than manually typing your code. On the other hand, rather than us giving you laborious, step-by-step instructions on building each page, it is more efficient, more flexible for you, and less error prone to just show you the finished product as a screenshot and/or an .aspx page.
The goal is not for you to type in the entire .aspx page, but rather for you to read through the content presented here and recreate it on your own machine, using whatever combination of drag and drop and manual editing works best for you.
The first thing you notice is t hat the name of the web site (shown in the URL in Fig.34) is ASPNETServerControlBasics. Open a new web site and name it ASPNETServerControlBasics. Open that web site's default.aspx page.
Notice in above Example that the title is set (ASP.NET Server Controls - Basics). Set that in your default.aspx by typing directly into the file.
Next, notice the two HTML header elements: an h1 and an h2. Those, too, are typed directly into the Source view of default.aspx since the HTML section of the Toolbox does not include any header controls. Here, however, Intellisense helps as soon as you type the opening angle bracket by dropping down a list of all the possible elements that can legally go inside a pair of angle brackets. This list dynamically reflects all the possibilities as you enter each character.
Next, drag a Label control onto the page from the Standard section of the Toolbox, onto either the Source or Design views. The advantage of doing this in Design view is that it is a bit easier to generate the event handlers.
With the cursor on this Label button on the page, again in either Source or Design view, the Properties window will show the current properties of the control. Change the ID from the default Label1 to lblTime. Delete the contents of the Text property.
Alternatively, you can type the control declarations directly on the Source view, without using the Properties window. Intellisense will help by popping up lists of all the possible attributes (properties) and events. If you change any view or Properties window, all the other views and windows will immediately reflect the change.
The advantage of presenting the .aspx to you in this way is that it is clear what your code should look like when you are done, and you can build that code by hand or by using drag and drop and/or the Properties windowyour choice. In fact, if you prefer not to do any of that work, you can download the completed source code from the Liberty Associates web site as described in the Preface.
Example. lblTime Init event handler code for WebServerControlBasics1

Run the page either by pressing F5 or selecting the Debug Start menu item. You will see something similar to that shown in Figure 4-1.
These two examples demonstrate a Label control, an event handler, and properties being set for a control.
This simple web page has static text and a web server Label control. The Label control has been assigned an id of lblTime, which allows the control to be referred to elsewhere in the code.
Of more interest is the onInit attribute, which defines an event handler for the Init event. The Init event, a member of the Control class, is called when a control is initialized. It is the first step in each control's life cycle. All WebControls, since they are derived from Control, have an Init event.
The Init event is handled by a method called lblTime_Init, defined in the code block at the top of the .aspx file or in the code-behind file, respectively. The lblTime_Init method sets several properties of the label's font (Name, Size, and so on) and sets the value of the Text property. The Text property value is a concatenation of the current date and time, a literal string, and the name of the font used. Because DateTime.Now is of type DateTime, it must be converted to a string in the C# code.
The results, shown in Fig.34, are not pretty, but they are instructive. The figure shows how several text attributesbold, italic, overline, underline, and strikeout-- can be applied to a label.
Fonts deserve special mention. Fonts contain subproperties, which are listed in below Table. When used in HTML, subproperties are accessed declaratively in code in the form:
Font-Italic