Building Websites with Web Forms

For many years, ASP.NET has been evolving website development with a rich set of server-side controls that do a lot of the client-server communication and HTML rendering tough stuff on the developer’s behalf. Visual Studio 2015 continues to enable developers to take advantage of this design-time richness and productivity. However, modern, responsive UIs that leverage the many JavaScript frameworks often require more direct access to the HTML and CSS than what is available when the HTML is emitted on your behalf (as it is in Web Forms). For this reason, Web Forms have diminished in popularity (for new development) in favor of ASP.NET MVC and SPAs. That said, there are still many business applications taking big advantage of the developer productivity of drag-and-drop, an event-driven model, and the overall simplicity Web Forms has to offer.

Developers building with Web Forms do so because Web Forms include the productivity-enhancing, rich set of design-time controls. These controls make handling and binding to data easier. They allow for validation, viewstate, and postback. They emit HTML on the developer’s behalf. And, of course, they make coding with them on server side much easier. Figure 1.7 shows just some of the controls (and control groups) that are available to Web Forms developers. The Standard group is shown as icons only to help you get a feel for the volume of controls.

Image

FIGURE 1.7 The rich set of server-side controls for building Web Forms websites.

Develop and Design at the Same Time

You develop ASP.NET Web Forms pages by designing with controls and connecting code to those controls. The code for the design is referred to as markup. This is XHTML that defines the controls, their layout, and their look on your page. The Web Forms tools include both a markup editor and a visual WYSIWYG designer for laying out your page. You can switch between the source (XHTML) and the design (WYSIWYG) view of a web form many times during development. The source view allows you full access to editing the XHTML of the page. Design view lets you see the page develop and gives access to the many shortcuts attached to controls in the designer. Visual Studio makes switching between these views simple. It also provides a split view. With it, you can see both the XHTML and the visual designer. Figure 1.8 shows an example.

Image

FIGURE 1.8 The Web Forms designer split view.

Split view tries to keep both the source and the design in sync. This works when you drag items from the Toolbox to either the source or the design view panes. However, the design view can get out of sync when you are doing a lot of edits to your source. In these cases, the design view indicates that it is out of sync. Click on the designer, and everything is back in sync.

Centrally Manage Navigation and Design

Visual Studio 2005 first introduced the capability to create master pages. These pages centralize the management of a site’s design and navigation elements. In addition, master pages are supported by the designer, which allows for a richer design experience. A developer can see the page in the context of the site’s central design while in design mode.

You create a master page by selecting the Master Page template from the Add New Item dialog. You then define your site navigation, header and footer information, styles, and anything else that should apply to each page in the site (or subarea of a site). After you define the navigation, you can create new web forms that provide specific content that should be enclosed inside a master page. Figure 1.9 shows an example of working with a web form whose outer header content is based on a master page.

Image

FIGURE 1.9 Web Forms pages that use a master page.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset