Lab 4: Server Controls Walkthrough
Visual Studio Team
Microsoft Corporation
August 2001
Summary: This hands-on lab provides an ASP.NET programming model that illustrates a few ASP.NET server controls and the C# page source. (4 printed pages)
Download the Experience Visual Studio .NET Lab files from the introduction topic.
Contents
Introduction
Viewing the Server Controls
Viewing the Source
Closing Out of Lab 4
Introduction
This hands-on lab provides an ASP.NET programming model that illustrates a few ASP.NET server controls and the C# page source. These controls behave like client-side controls, but can be run on the server. The result is that the page is buffered in memory until the event is handled and a result is processed. Then the entire page is sent back to the browser.
Viewing the Server Controls
- To view the server controls, click Start, click Programs, click Experience VS .NET Content, click Lab 4, and then click Server Controls. The screen shown in Figure 1 appears.
Figure 1. Server controls
- In the Name field, type your name (Daniel is used in Figure 2), and click Lookup.
Figure 2. Lookup screen
Note When you click the Lookup button, the values of the Name control and the Category control are posted back to the server. This is where the values are used to generate a new page that is then sent back to the browser after processing. This is done using server-side script.
Viewing the Source
To view the source page, click Start, click Programs, click Experience VS .NET Content, click Lab 4, and then click Server Controls C#. The screen shown in Figure 3 appears.

Figure 3. Server controls C# source page
Note On the page shown in Figure 3, you can view the C#, VB and Jscript versions of the code by clicking the links at the top of the page. Also note the way the AdRotator control accesses an XML page as its source, or AdvertisementFile. To view the code mentioned in the following examples, you may have to scroll down the page in the browser window.
In ASP.NET, you can write code to control the click event associated with buttons. In this example, the action in response to clicking the "Name" Button control was to change the value of the "Message" Label control. The event is sent back to the server, where it is processed. During the processing, the page image is buffered so that the entire page is sent back to the browser only when the script is completely processed.
Note Notice the way in which the properties are accessed (that is, Message.Text and Name.Text). If you are accustomed to using Visual Basic, then the use of the period operator will seem quite natural. You can access and assign properties in this way.
Another feature of ASP.NET is the availability of the server side Page_Load event, which is similar to the Form_Load event in Visual Basic. This feature allows you to program specific initializing code that sets environment variables or properties of controls in the page. For example, you can set the text property of a button to be based on data from an external data source.
Closing Out of Lab 4
When you have finished browsing the ASP.NET programming model, server controls, and C# source, close all the windows.
Other articles and labs in the Experience Visual Studio .NET set include:
Introducing the Visual Studio .NET Lab Series
Lab 5: Using the Visual Basic Upgrade Wizard