16.1 Creating a Simple Web Form

 <  Day Day Up  >  

You want to create a new ASP .NET Web application.


Technique

To create a new Web application, use the New Project dialog box and use the ASP.NET Web Application project template. The location box displays a different path from what you have used so far. Instead of an absolute path to the project's source code, a virtual directory is created within Internet Information Server (IIS). After you create the project, the Web Forms designer opens to allow you to design the initial Web Form. The next recipe explains how to use the Web Forms designer to add server-side controls to the page.

Comments

Working with a Web Form is similar to working with a Windows Form in that you use a designer to design the form and a source file to control the behavior of the form at runtime. However, Windows Forms information is contained within a single source file, whereas a Web Form contains both an HTML-based file for presentation and a corresponding C# file for the Web Form logic. To view the HTML associated with the ASP.NET page, open the default WebForm1.aspx file and click on the bottom-left button labeled HTML. To switch back to design view, click the design button.

The first thing you'll notice in the HTML for the .aspx page is the @Page directive. ASP.NET uses this directive during runtime to determine the correct assembly to use when the page is requested as well as certain attributes that control how the page is processed by ASP.NET. The rest of the page is regular HTML because nothing has been added for server-side processing.

The C# file that is generated is known as the code-behind file because it is literally the code that is behind the main page controlling the behavior of server-side controls as they are processed by ASP.NET. To open the source file, right-click on the WebForm1.aspx file within Solution Explorer and select View Code. Within the generated code is the Page_Load method. As its name implies, this method is called each time a page is loaded by ASP.NET. This loading occurs on the server before the final HTML is generated, and it is where initialization code is placed. If you expand the source code region named Web Form Designer generated code, you'll see that the Page_Load is actually an event handler for the Load event defined in the System.Web.Page class, which your Web Form class derives from. Event handlers are discussed in detail in Recipe 16.3, "Handling Web Control Events."

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net