Chapter 5 Working with the Page

 

Overview

Although formless pages are still accepted and correctly handled, the typical ASP.NET page contains a single <form> tag decorated with the runat attribute set to server. On the server, the <form> tag is mapped to an instance of the HtmlForm class. The HtmlForm class acts as the outermost container of all server controls and wraps them in an HTML <form> element when the page is rendered. The obtained HTML form posts to the same page URL and for this reason is said to be reentrant. The default method used to submit form data is POST, but GET can be used as well.

In most cases, the server form is the outermost tag of the page and is contained directly in <body>. In general, though, the server <form> tag can be the child of any other server container control, such as <table>, <div>, <body>, and any other HTML generic control. (We covered HTML controls and Web controls in Chapter 4.) If any noncontainer controls (for example, a TextBox) are placed outside the form tag, an exception is thrown. Notice, though, that no check is made at compile time. The exception is raised by the control itself when the host page asks 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 write 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 touch on personalization a hot new feature of ASP.NET 2.0 and end by discussing tools and effective techniques to debug, trace, and handle errors.

 


Programming Microsoft ASP. Net 2.0 Core Reference
Programming Microsoft ASP.NET 2.0 Core Reference
ISBN: 0735621764
EAN: 2147483647
Year: 2004
Pages: 112
Authors: Dino Esposito
BUY ON AMAZON

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net