System.Web.UI.HtmlControls.HtmlForm Class

Provides programmatic access to the HTML <form> element on the server.

See Also: HtmlForm Members


public class HtmlForm : HtmlContainerControl


The System.Web.UI.HtmlControls.HtmlForm control is a container for server controls on a Web Forms page. All server controls that post back to the server must be placed between the opening and closing tags of an System.Web.UI.HtmlControls.HtmlForm control.


ASP.NET allows only a single System.Web.UI.HtmlControls.HtmlForm control to be active on a Web Forms page. If there is more than one active System.Web.UI.HtmlControls.HtmlForm control on a Web Forms page, the common language runtime will throw an System.Web.HttpException exception when you request the page. You can, however, use a System.Web.UI.WebControls.MultiView control where each System.Web.UI.WebControls.View object contains one System.Web.UI.HtmlControls.HtmlForm control, because only one System.Web.UI.WebControls.View is active at any given time.

You can control the behavior of the System.Web.UI.HtmlControls.HtmlForm control by setting its properties. To specify the encoding type for the form's data, set the HtmlForm.Enctype property. The method (GET or POST) that a browser uses to post form data to the server for processing is specified by setting the HtmlForm.Method property.


By default, the HtmlForm.Method property is set to POST. You can modify the value of this property to GET, but this might break the built-in state and postback services provided by the ASP.NET page framework.

You can configure controls that implement the System.Web.UI.WebControls.IButtonControl interface to post to a different target page. This is referred to as cross-page posting. For more information, see Cross-Page Posting in an ASP.NET Web Page.

For a list of initial property values for an instance of System.Web.UI.HtmlControls.HtmlForm, see the HtmlForm.#ctor constructor.


Namespace: System.Web.UI.HtmlControls
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 1.0.5000.0,