Web Forms Are Server Side Objects

To create a C# Web application, click the New Project button from the Visual Studio (VS) start page to display the New Project dialog. Next, select C# Projects from the Project Types list, and then click the ASP.NET Web Application icon in the Templates pane of the dialog (see Figure 5.1). The fact that you must select the ASP.NET project type to create a C# Web application should reinforce the idea that C# Web applications and ASP.NET Web applications are the same thing.

When you first create an ASP.NET Web application project, C# adds a file called (by default) WebForm1.aspx to your workspace. This file is marked as the startup page and is the Web equivalent of a VB6 standard project's Form1.frm. You can compile and run the program, and C# will open a browser instance and call the Web Form1.aspx file. However, you won't see anything because the page has no content and no controls. By default, it's a blank page.

The key to working efficiently with Web Forms is to think of them as templates for content—and that content usually comes from the server, from the code-behind code. Therefore, while you can create and use Web Forms just as you may have built ASP pages in the past, it's not the most efficient way to use them. Instead, try to think of Web Forms in exactly the same way you think of Windows Forms—as templates to hold information. For example, consider the MessageBox class in C# (similar to the MsgBox function in VBScript—and similar to an alert in JScript). You can control the content of the message display, the title, text, and buttons, but you don't need to alter the window display to make efficient use of message boxes. Web Forms are similar. Try to build Web Forms that you can reuse for many different purposes.

Figure 5.1: Visual Studio New Project dialog: Create a C# Web application

Was this article helpful?

0 0

Post a comment