This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!
Introduction to Web Forms
Web Forms are an ASP+ technology that you use to create programmable Web pages. They can present information, using any markup language, to the user in any browser and use code on the server to implement application logic.
Web Forms:
- Can run on any browser and automatically render the correct, browser-compliant HTML for features such as styles, layout, and so on. Alternatively, you can design your Web form to run on a specific browser such as Microsoft® Internet Explorer 5 and take advantage of the features of a rich browser client.
- Can be programmed in any NGWS runtime and frameworks language, including Microsoft® Visual Basic, Microsoft® C#, Microsoft® Managed Extensions for C++, and Microsoft® JScript.
- Are built on NGWS runtime and provide all the benefits of those technologies, including a managed execution environment, type safety, inheritance, and dynamic compilation for improved performance.
- Support WYSIWYG editing tools and powerful RAD dvelopment tools, such as Microsoft® Visual Studio®, for designing and programming your forms.
- Support a rich set of controls that allows developers to cleanly encapsulate page logic into reusable components and declaratively handle page events.
- Allow for separation between code and content on a page, eliminating the "spaghetti-code" often found in ASP pages.
- Provide a set of state management features that preserve the view state of a page between requests.
- Are extensible with user-created and third-party controls.
Components of Web Forms
Web Forms divide the Web applications user interface into two pieces: the visual component and the user interface logic. If you have worked with rapid application deployment tools, like Microsoft® Visual Basic® and Microsoft® Visual C, in the past, you will recognize this distinction between the visible portion of a form and the code that interacts with the form.
The user interface for Web Forms pages consists of a file containing markup and Web-Forms–specific elements. This file is referred to as the page. The page works as a container for the text and controls you want to display. Using any HTML editor plus Web Forms Server Controls, you can lay out the form as you like. The page is a file with the extension ".aspx."
User interface logic for the Web form consists of code that you create to interact with the form. You can choose that the programming logic reside in the .aspx file, or in a separate file (referred to as the "code-behind" file), written in Visual Basic or C#. When you run the form, the code-behind class file runs and dynamically produces the output for your page.
For more details about how Web Forms are constructed, see Web Forms Code Model.
What Web Forms Help You Accomplish
Web application programming presents challenges that do not typically arise when programming traditional client-based applications. Among the challenges are these:
- Rich user interface. A user interface with a large amount of content, a complex layout, and rich user interaction can be difficult and tedious to create and program using basic HTML facilities. It is especially hard to create a rich user interface for applications likely to run in many different browsers.
- 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 only exchange 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, servers have no memory of pages that they have 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. Each of these browsers has different capabilities, making it difficult to create an application that will run equally well on all of them.
- Data access. Reading from and writing to a data source in traditional Web applications can be complicated and resource-intensive.
Meeting these challenges for Web applications can require substantial time and effort. Web Forms address these challenges in the following ways:
- Browser-independent applications. Web Forms provide a framework 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 to provide improved performance and a richer client experience.
- Event-based programming model. Web Forms bring to Web applications the model of writing event-handling methods for events that occur in either the client or server. The Web Forms 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 handler is all automatic and invisible. The result is a clear, easily written code structure.
- Abstract, intuitive, consistent object model. The Web Forms framework presents an object model that allows you to think of your forms as a unit, not as separate client and server pieces. In the Web Forms model, you can program the form in a much more intuitive way than in traditional Web applications, including the ability to set properties for form elements and respond to events. In addition, Web Forms 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 Web Forms 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.
- State management. The Web Forms framework automatically handles the task of maintaining the state of your form and its controls, and provides you with explicit ways to maintain the state of application-specific information. This is accomplished without heavy use of server resources and without sending cookies to the browser, two traditional means for storing state.
- Scalable server performance. The Web Forms framework allows you to scale your 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
Creating ASP+ Web Applications