HtmlForm Server Control Declarative Syntax
Creates a server-side control that maps to the <form> HTML element and allows you to create a container for elements in a Web page.
<form
DefaultButton="string"
DefaultFocus="string"
EnableViewState="False|True"
Id="string"
SubmitDisabledControls="False|True"
Visible="True|False"
OnDataBinding="OnDataBinding event handler"
OnDisposed="OnDisposed event handler"
OnInit="OnInit event handler"
OnLoad="OnLoad event handler"
OnPreRender="OnPreRender event handler"
OnUnload="OnUnload event handler"
runat="server"
>
<!--Other controls, input forms, and so on.-->
</form>
Use the HtmlForm control to program against the HTML <form> element. To take advantage of postback services, all Web Forms controls, whether HTML controls, Web controls, user controls, or custom controls, must be nested between well-formed opening and closing tags of the HtmlForm control. If the tags are not closed properly, ASP.NET will not recognize the element. Either the element will be ignored or a compilation error will occur, depending on how the element is formed.
Note |
|---|
You cannot include more than one HtmlForm control on a single Web Forms page. |
By default, the HtmlForm control's method attribute is set to POST. You can customize the method attribute to suit your needs, but setting the method attribute to a value other than GET or POST can break the built-in view state and postback services provided by ASP.NET.
Note |
|---|
The action attribute is always set to the URL of the page itself. The action attribute cannot be changed; therefore, you can only post back to the page itself. |
Note |
|---|
The name attribute for form elements is deprecated in XHTML 1.1. Therefore, this control does not render the name attribute in ASP.NET 4. |
The following example shows three HtmlButton controls with a separate OnServerClick handler for each button. Each of these events causes a postback to the server (the HtmlForm control is required for any scenario in which a postback occurs). This example also demonstrates that only one HtmlForm control is allowed on a Web Forms page, including a form that supports multiple events. If you include more than one HtmlForm control, the .NET Framework will throw an exception.
Note