Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Build Your Own ASP.NET 2.0 Web Site Using CSharp And VB (2006) [eng]-1.pdf
Скачиваний:
143
Добавлен:
16.08.2013
Размер:
15.69 Mб
Скачать

4

Constructing ASP.NET Web Pages

 

If you’ve ever built a model from Lego bricks, you’re well prepared to start building real ASP.NET web pages. ASP.NET offers many techniques that allow web developers to build parts of web pages independently, then put them together later to build complete pages.

The content we’re organizing through our work with ASP.NET is almost never static. At design time, we tend to think in terms of templates that contain placeholders for the content that will be generated dynamically at runtime. And to fill those placeholders, we can either use one of the many controls ASP.NET provides, or build our own.

In this chapter, we’ll discuss many of the objects and techniques that give life and color to ASP.NET web pages, including:

web forms

HTML server controls

web server controls

web user controls

master pages

Chapter 4: Constructing ASP.NET Web Pages

handling page navigation

styling pages and controls with CSS

If the list looks intimidating, don’t worry—all of this is far easier to understand than it might first appear.

Web Forms

As you know, there’s always new terminology to master when you’re learning new technologies. But with ASP.NET, even the simplest terms that are used to describe the basics of web pages change to reflect the processes that occur within them.

The term used to describe an ASP.NET web page is web form, and this is the central object in ASP.NET development. You’ve already met web forms—they’re the .aspx files you’ve worked with so far in this book. At first glance, web forms look much like HTML pages, but in addition to static HTML content they also contain ASP.NET presentational elements, and code that executes on the server side to generate dynamic content and perform the desired server-side functionality.

Every web form includes a <form runat="server"> tag, which contains the ASP.NET-specific elements that make up the page. Multiple forms aren’t supported. The basic structure of a web form is shown here:

<html>

<head>

<script runat="server" language="language">

…code here…

</script>

</head>

<body>

<form runat="server">

…user interface elements here…

</form>

</body>

</html>

To access and manipulate a web form programatically, we use the

System.Web.UI.Page class. You might recognize this class from the code-behind example we saw in Chapter 3. We must mention the class explicitly in the codebehind file. In situations in which we’re not using code-behind files (i.e. we write

94