Online Book Reader

Home Category

Programming Microsoft ASP.NET 4 - Dino Esposito [195]

By Root 5693 0
and closing tags of the form.

InnerText

Inherited from HtmlContainerControl, gets or sets the text between the opening and closing tags of the form.

Method

Gets or sets a value that indicates how a browser posts form data to the server. The default value is POST. It can be set to GET if needed.

Name

Gets the value of UniqueID.

Style

Gets a collection of all cascading style sheet (CSS) properties applied to the form.

SubmitDisabledControls

Indicates whether to force controls disabled on the client to submit their values, allowing them to preserve their values after the page posts back to the server. False by default.

TagName

Returns “form”.

Target

Gets or sets the name of the frame or window to render the HTML generated for the page.

UniqueID

Inherited from Control, gets the unique, fully qualified name of the form.

Visible

Gets or sets a value that indicates whether the form is rendered. If this property is set to false, the form is not rendered to HTML.

The form must have a unique name. If the programmer doesn’t assign the name, ASP.NET uses a default name—aspnetForm. The programmer can set the form’s identifier by using either the ID or Name property. If both are set, the ID attribute takes precedence. (Note, though, that any reliance on the Name attribute compromises the XHTML compliance of the page.)

The parent object of the form is the outer container control with the runat attribute. If such a control doesn’t exist, the page object is set as the parent. Typical containers for the server form are and
if they are marked as server-side objects.

By default, the Method property is set to POST. The value of the property can be modified programmatically. If the form is posted through the GET method, all form data is passed on the URL’s query string. However, if you choose the GET method, make sure the size allowed for a GET request does not affect the integrity of your application or raise security issues.

Methods of the HtmlForm Class


Table 9-2 lists the methods available on the HtmlForm class that you’ll be using more often. All the methods listed in the table are inherited from the base System.Web.UI.Control class.

Table 9-2. Form Methods

Method

Description

ApplyStyleSheetSkin

Applies the style properties defined in the page style sheet.

DataBind

Calls the DataBind method on all child controls.

FindControl

Retrieves and returns the control that matches the specified ID.

Focus

Sets input focus to a control.

HasControls

Indicates whether the form contains any child controls.

RenderControl

Outputs the HTML code for the form. If tracing is enabled, it caches tracing information to be rendered later, at the end of the page.

Note that the FindControl method searches only among the form’s direct children. Controls belonging to an inner naming container, or that are a child of a form’s child control, are not found.

Multiple Forms


As mentioned, the single-form model is the default in ASP.NET and plays a key role in the automatic view state management mechanism I described in Chapter 5. Generally speaking, the ASP.NET’s enforcement of the single-form model does not significantly limit the programming power, and all things considered, doing without multiple forms is not a big sacrifice. Some pages, though, would have a more consistent and natural design if they could define multiple logical forms. In this context a logical form is a logically related group of input controls. For example, think of a page that provides some information to users but also needs to supply an additional form such as a search or login box.

You can incorporate search and login capabilities in ad hoc classes and call those classes from within the page the user has displayed. This might or might not be the right way to factor your code, though. Especially if you’re porting some old code to ASP.NET, you might find it easier to insulate login or search code in a dedicated page. Well, to take advantage of form-based login, how do you post input data to this

®Online Book Reader