This documentation is archived and is not being maintained.

Introduction to Web Forms Pages

Visual Studio .NET 2003

You can use Web Forms pages to create programmable Web pages that serve as the user interface for your Web application. A Web Forms page presents information to the user in any browser or client device and implements application logic using server-side code. Web Forms page output may contain almost any HTTP-capable language, including HTML, XML, WML, and ECMAScript (JScript, JavaScript).

Web Forms pages are:

  • Based on Microsoft ASP.NET technology in which code that runs on the server dynamically generates Web page output to the browser or client device. For details about ASP.NET, see ASP.NET Technology Backgrounder.
  • Compatible with any browser or mobile device. A Web Forms page automatically renders the correct browser-compliant HTML for features such as styles, layout, and so on. Alternatively, you can design your Web Forms pages to run on a specific browser such as Microsoft Internet Explorer 5 and take advantage of the features of a rich browser client.
  • Compatible with any language supported by the .NET common language runtime, including Microsoft Visual Basic, Microsoft Visual C#, and Microsoft JScript .NET.
  • Built on the Microsoft .NET Framework. This provides all the benefits of the framework, including a managed environment, type safety, and inheritance.
  • Supported in Visual Studio with powerful rapid application development (RAD) tools for designing and programming your forms.
  • Extensible using controls that provide RAD capability for Web development, allowing you to create rich user interfaces quickly.
  • Flexible because you can add user-created and third party controls to them.

Components of Web Forms

In Web Forms pages, the user interface programming is divided into two distinct pieces: the visual component and the logic. If you have worked with tools like Visual Basic and Visual C++ in the past, you will recognize this division between the visible portion of a form and the code behind the form that interacts with it.

The visual element is referred to as the Web Forms page. The page consists of a file containing static HTML, or ASP.NET server controls, or both simultaneously.

The Web Forms page works as a container for the static text and controls you want to display. Using the Visual Studio Web Forms Designer plus ASP.NET server controls, you can design the form as you would in any Visual Studio application. For more information, see Controls You Can Use on Web Forms Pages.

The logic for the Web Forms page consists of code that you create to interact with the form. The programming logic resides in a separate file from the user interface file. This file is referred to as the "code-behind" file and has an ".aspx.vb" or ".aspx.cs" extension. The logic written in the code-behind file can be written in Visual Basic or Visual C#.

Web Forms File Structure


The code-behind class files for all Web Forms pages in a project are compiled into the project dynamic-link library (.dll) file. The .aspx page file is also compiled, but somewhat differently. The first time a user browses to the .aspx page, ASP.NET automatically generates a .NET class file that represents the page, and compiles it to a second .dll file. The generated class for the .aspx page inherits from the code-behind class that was compiled into the project .dll file. When a user requests the Web page URL, the .dll files run on the server and dynamically produce the HTML output for your page. For more information, see Web Forms Page Processing.

For more information about how Web Forms pages are constructed, see Web Forms Code Model.

What Web Forms Pages Help You Accomplish

Web application programming presents challenges that do not typically arise when programming traditional client-based applications. Among the challenges are:

  • Implementing a rich Web user interface. A user interface with a complex layout, a large amount of dynamic content, and full-featured user-interactive objects can be difficult and tedious to design and implement using basic HTML facilities. It is particularly difficult to create a rich user interface for applications likely to run on many different browser and client device platforms.
  • Separation of client and server. In a Web application, the client (browser) and server are different programs often running on different computers (and even on different operating systems). Consequently, the two halves of the application share very little information; they can communicate, but typically exchange only small chunks of simple information.
  • Stateless execution. When a Web server receives a request for a page, it finds the page, processes it, sends it to the browser, and then, effectively, discards all page information. If the user requests the same page again, the server repeats the entire sequence, reprocessing the page from scratch. Put another way, a server has no memory of pages that it has processed. Therefore, if an application needs to maintain information about a page, this becomes a problem that has to be solved in application code.
  • Unknown client capabilities. In many cases, Web applications are accessible to many users using different browsers. Browsers have different capabilities, making it difficult to create an application that will run equally well on all of them.
  • Complications with data access. Reading from and writing to a data source in a traditional Web applications can be complicated and resource-intensive.
  • Complications with scalability. In many cases Web applications designed with existing methods fail to meet scalability goals due to the lack of compatibility between the various components of the application. This is often the single failure point for applications under a heavy growth cycle.

Meeting these challenges for Web applications can require substantial time and effort. Web Forms pages and the ASP.NET page framework address these challenges in the following ways:

  • Intuitive, consistent object model. The ASP.NET page framework presents an object model that allows you to think of your forms as a unit, not as separate client and server pieces. In this model, you can program the form in a more intuitive way than in traditional Web applications, including the ability to set properties for form elements and respond to events. In addition, ASP.NET server controls are an abstraction from the physical contents of an HTML page and from the direct interaction between browser and server. In general, you can use server controls the way you might work with controls in a client application and not have to think about how to create the HTML to present and process the controls and their contents.
  • Event-driven programming model. Web Forms pages bring to Web applications the familiar model of writing event handlers for events that occur on either the client or server. The ASP.NET page framework abstracts this model in such a way that the underlying mechanism of capturing an event on the client, transmitting it to the server, and calling the appropriate method is all automatic and invisible to the implementer. The result is a clear, easily written code structure that supports event-driven development.
  • Intuitive state management. The ASP.NET page framework automatically handles the task of maintaining the state of your form and its controls, and it provides you with explicit ways to maintain the state of application-specific information. This is accomplished without heavy use of server resources and can be implemented with or without sending cookies to the browser.
  • Browser-independent applications. The ASP.NET page framework provides for creating all application logic on the server, eliminating the need to explicitly code for differences in browsers. However, it still allows you to automatically take advantage of browser-specific features by writing client-side code to provide improved performance and a richer client experience.
  • .NET Framework common language runtime support. The ASP.NET page framework is a technology of ASP.NET. ASP.NET is built on the .NET Framework, so the entire framework is available to any ASP.NET application. Your applications can be authored in any language compatible with the runtime, including Microsoft Visual Basic, Visual C#, and JScript .NET. In addition, data access is simplified using the data access infrastructure provided by the .NET Framework, including ADO.NET.
  • .NET Framework scalable server performance. The ASP.NET page framework allows you to scale your Web application from one computer with a single processor to a multi-computer "Web farm" cleanly and without complicated changes to the application's logic.

See Also

ASP.NET Technology Backgrounder | Web Forms Code Model | Web Forms Page Processing | Walkthrough: Creating a Basic Web Forms Page | Migrating to Web Forms | Walkthrough: Creating an Accessible Web Application