Notepad, but youll gradually learn how to use Visual Web Developer to ease
some of the tasks well tackle.
So lets install this tool to make sure well have it ready when we need it.
1.
Go to http://msdn.microsoft.com/vstudio/express/vwd/ and click the Download
link.
2. Execute the downloaded file.
3. Accept the default options. At one point, youll be asked about installing Mi-
crosoft MSDN 2005 Express Edition, which is the products documentation.
It wouldnt hurt to install it, but you need to be patient, because its quite big.
(Note that youve already installed the .NET Framework 2.0 documentation,
together with the SDK.)
Bonus!
If youve already installed the .NET Framework 2.0 SDK, youve already
installed Microsoft MSDN 2005 Express Edition.
In this book, well start using Visual Web Developer to build real web applications
in Chapter 5. Until then, well create examples using Notepad (or another simple
text editor) so youre prepared to take full advantage of the features offered by
Visual Web Developer when the time comes to use it.
Writing your First ASP.NET Page
For your first ASP.NET exercise, well create the simple example shown in Fig-
ure 1.15.
Figure 1.15. Your first ASP.NET page
26
Chapter 1: Introducing ASP.NET and the .NET Platform
Lets get started! Open your text editor (Notepad is fine). If you have software
that creates ASP.NET pages automatically, such as Visual Studio .NET or Visual
Web Developer 2005 Express Edition, please dont use it yetwhile these are
great tools that allow you to get up and running quickly, they do assume that
you already understand how ASP.NET works.
So, open your text editor, and create a new file named FirstPage.aspx in the
Learning folder you created earlier. Start editing FirstPage.aspx by entering
the HTML for our page, shown below:
File: FirstPage.aspx (excerpt)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>My First ASP.NET 2.0 Page</title>
</head>
<body>
<p>Hello there!</p>
<p>The time is now: </p>
</body>
</html>
So far, so good, right? Now, lets add some ASP.NET code that will create the
dynamic elements of the page, starting with the time.
File: FirstPage.aspx (excerpt)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>My First ASP.NET 2.0 Page</title>
</head>
<body>
<p>Hello there!</p>
<p>The time is now:
<asp:Label runat="server" id="timeLabel" /></p>
</body>
</html>
Weve added an <asp:Label/> tag to the document. This is a special tag that
lets us insert dynamic content into the page. The asp: part of the tag name
identifies it as a built-in ASP.NET tag. ASP.NET comes with numerous built-in
tags; <asp:Label/> is one of the simplest.
27
Writing your First ASP.NET Page
The runat="server" attribute identifies the tag as something that needs to be
handled on the server. In other words, the web browser will never see the
<asp:Label/> tag; when the page is requested by the client, ASP.NET sees it
and converts it to regular HTML tags before the page is sent to the browser. Its
up to us to write the code that will tell ASP.NET to replace this particular tag
with the current time.
To do this, we must add some script to our page. ASP.NET gives you the choice
of a number of different languages to use in your scripts. The two most common
languages are VB and C#. Lets take a look at examples using both. Heres a
version of the page in VB:
Visual Basic File: FirstPage.aspx (excerpt)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>My First ASP.NET Page</title>
<script runat="server" language="VB">
Sub Page_Load(sender As Object, e As EventArgs)
timeLabel.Text = DateTime.Now.ToString()
End Sub
</script>
</head>
<body>
<p>Hello there!</p>
<p>The time is now:
<asp:Label runat="server" id="timeLabel" /></p>
</body>
</html>
Heres the same page written in C#:
C# File: FirstPage.aspx (excerpt)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>My First ASP.NET Page</title>
<script runat="server" language="C#">
protected void Page_Load(object sender, EventArgs e)
{
timeLabel.Text = DateTime.Now.ToString();
}
</script>
28
Chapter 1: Introducing ASP.NET and the .NET Platform

Get Build Your Own ASP.NET 2.0 Web Site Using C# & VB, Second Edition 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.