, , and any other HTML generic control. (I covered HTML controls and Web controls in Chapter 6.) If any noncontainer server controls (for example, a TextBox) are placed outside the form tag, an exception is thrown as the page executes—no check is made at compile time. The exception is raised by the control itself when the host page begins to render. Noncontainer Web controls, in fact, check whether they are being rendered within the boundaries of a server form and throw an HttpException if they are not. A call to the Page’s VerifyRenderingInServerForm method does the job. (Be aware of this virtuous behavior when you get to writing custom controls.)
In this chapter, we’ll examine some aspects of form-based programming in ASP.NET, including how to use multiple forms in the same page and post data to a different page. We’ll also touch on input validation and validation controls.
Programming with Forms
One of the most common snags Web developers face when they first approach the ASP.NET lifestyle is the fact that managed Web applications support the single-form interface model. In the single-form interface model, each page always posts to itself and doesn’t supply any hook for developers to set the final destination of the postback. What in HTML programming is the Action property of the form is simply not defined on the ASP.NET HtmlForm class. By default, each ASP.NET page can post only to itself, unless some specific API extensions are used to perform a cross-page post. Unlike the action URL, the HTTP method and the target frame of the post can be programmatically adjusted using ad hoc HtmlForm properties—Method and Target.
The HtmlForm Class
The HtmlForm class inherits from HtmlContainerControl, which provides the form with the capability of containing child controls. This capability is shared with other HTML control classes, such as HtmlTable, characterized by child elements and a closing tag.
Properties of the HtmlForm Class
The HtmlForm class provides programmatic access to the HTML