Slide 10.c: ASP.NET Web pages
Slide 10.e: Adding simple code to a page
Home

Writing Your First ASP.NET Page


ASP.NET pages consist of code and markup and are dynamically compiled and executed on the server to produce a rendering to the requesting client browser. When a browser client requests .aspx resources, the ASP.NET runtime parses and compiles the target file into a .NET Framework class. This class can then be used to dynamically process incoming requests.

For example, the following sample demonstrates a simple HTML page that collects a user's name and category preference and then performs a form postback to the originating page when a button is clicked:

<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <body>
  <center>
   <form action="intro1_vb.aspx" method="post">
    <h3>Name: <input id="Name" type=text>
     Category:
     <select id="Category" size=1>
      <option>psychology</option>
      <option>business</option>
      <option>popular_comp</option>
     </select>
     <input type=submit value="Lookup">
    </h3>
   </form>
  </center>
 </body>
</html>



Note that nothing happens yet when you click the Lookup button. This is because the .aspx file contains only static HTML (no dynamic content). Thus, the same HTML is sent back to the client on each trip to the page, which results in a loss of the contents of the form fields (the text box and drop-down list) between requests.