HtmlForm Class

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

Namespace: System.Web.UI.HtmlControls
Assembly: System.Web (in system.web.dll)

public ref class HtmlForm : public HtmlContainerControl
public class HtmlForm extends HtmlContainerControl
public class HtmlForm extends HtmlContainerControl

The 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 HtmlForm control.


ASP.NET allows only a single HtmlForm control to be active on a Web Forms page. If there is more than one active 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 MultiView control where each View object contains one HtmlForm control, because only one View is active at any given time.

You can control the behavior of the HtmlForm control by setting its properties. To specify the encoding type for the form's data, set the 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 Method property.

Caution noteCaution

By default, the 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 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 ASP.NET Web Pages.

For a list of initial property values for an instance of HtmlForm, see the HtmlForm constructor.

The following code example demonstrates how to use the HtmlForm class to create a simple form.

No code example is currently available or this language may not be supported.

  • AspNetHostingPermission  for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
  • AspNetHostingPermission  for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions