5.7. Understanding ASP.NET Forms

In ASP.NET, server controls, such as the TextBox and DropDownList, must reside within a server-side form. In Design view, the development environment knows this rule and inserts controls in the right place.

To understand forms, it helps to analyze the behind-the-scenes markup. Listing 5-1 shows the code that appears in Source view when you add a single page called myform.aspx to your project.

Listing 5-1. The myform.aspx Source Code
<%@ Page Language="VB" %>                                                 →1

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0                              →3
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">                                                        →6
<script runat="server">                                                   →7

</script>                                                                 →9

<html xmlns="http://www.w3.org/1999/xhtml">                              →11
<head runat="server">                                                    →12
        <title>Untitled Page</title>
</head>                                                                  →14
<body>
       <form id="form1" runat="server">                                  →16
       <div>                                                             →17
       </div>

       </form>
</body>
</html>                                                                  →22

→1 The line <%@ Page Language="VB" %> is a Page directive. It provides important information to ASP.NET while it compiles and assembles the page on the server. In this case, the Language attribute's value is VB, meaning ASP.NET should expect Visual Basic code. This and other directives aren't sent as HTML to the browser.

→3-6 The markup starting with <!DOCTYPE and ending with dtd"> is sent to the browser as is. It describes the HTML standard to which this page conforms.

→7-9 The markup <script runat="server"></script> includes the important runat attribute with the value server. Computer code within these tags is processed ...

Get ASP.NET 3.5 For Dummies® 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.