Read Build Your Own ASP.NET 3.5 Website Using C# & VB Online
Authors: Cristian Darie,Zak Ruvalcaba,Wyatt Barnett
Tags: #C♯ (Computer program language), #Active server pages, #Programming Languages, #C#, #Web Page Design, #Computers, #Web site development, #internet programming, #General, #C? (Computer program language), #Internet, #Visual BASIC, #Microsoft Visual BASIC, #Application Development, #Microsoft .NET Framework
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-specific elements, and code that executes on the server
side.
Every web form includes a
Licensed to [email protected]
Constructing ASP.NET Web Pages
97
To access and manipulate a web form programmatically, we use the
System.Web.UI.Page class. You might recognize this class from the code-behind
example we saw in Chapter 3. W
e must mention the class explicitly in the codebehind file. In situations in which we’re not using code-behind files (that is, we’re writing all the code inside the
.aspx
file instead), the Page class is still used—we
just don’t see it.
We can use a range of user interface elements inside the form—including typical,
static HTML code—but we can also use elements whose values or properties can
be generated or manipulated on the server either when the page first loads, or when
the form is submitted. These elements—which, in ASP.NET parlance, are called
controls
—allow us to reuse common functionality, such as the page header, a calendar, a shopping cart summary, or a “Today’s Quote” box, for example, across multiple web forms. There are several types of controls in ASP.NET:
■ HTML server controls
■ web server controls
■ web user controls
■ master pages
There are significant technical differences between these types of controls, but what
makes them similar is the ease with which we can integrate and reuse them in our
web sites. Let’s take a look at them one by one.
HTML Server Controls
HTML server controls are outwardly identical to plain old HTML tags, but include
a runat="server" attribute. This gives the ASP.NET runtime control over the HTML
server controls, allowing us to access them programmatically. For example, if we
have an tag in a page and we want to be able to change the address to which it
links dynamically, using VB or C# code, we use the runat="server" attribute.
A server-side HTML server control exists for each of HTML’s most common elements.
Creating HTML server controls is easy: we simply stick a runat="server" attribute
on the end of a normal HTML tag to create the HTML control version of that tag.
The complete list of current HTML control classes and their associated tags is given
Licensed to [email protected]
98
Build Your Own ASP.NET 3.5 Web Site Using C# & VB
Table 4.1. HTML control classes
Class
Associated Tags
HtmlAnchor
HtmlButton
HtmlForm