ASP.NET HtmlForm Control

Definition and Usage

The HtmlForm control is used to control the <form> element. In HTML, the <form> element is used to create forms.

Note:All HTML server controls must be located within the HtmlForm control!

Note:In a single page, you can only use one HtmlForm control!

Properties

Properties Description
Action

URL, defines where to send the data when the form is submitted.

Note: This property is always set to the URL of the page itself!

Attributes Returns all attribute names and value pairs of the element.
Disabled Boolean value indicating whether the control is disabled. The default is false.
EncType The MIME type used to encode the form content.
id The unique id of the control.
InnerHtml

Sets or returns the content between the start and end tags of the HTML element.

Special characters are not automatically converted to HTML entities.

InnerText

Sets or returns all text between the start and end tags of the HTML element.

Special characters are automatically converted to HTML entities.

Method The method by which the form sends data to the server. Valid values are "post" and "get". The default is "post".
Name The name of the form.
runat Specifies that the control is a server control. It must be set to "server".
Style Sets or returns the CSS properties applied to the control.
TagName Returns the tag name of the element.
Target The target window for loading the URL.
Visible Boolean value indicating whether the control is visible.

Example

HTMLForm
In this example, we have declared an HtmlInputText control, an HtmlInputButton control, and an HtmlGeneric control (remember to nest this control within the HtmlForm control). When the submit button is triggered, the submit subroutine will be executed. This submit subroutine will write a welcome message to the p element.