html form-control,HtmlForm Control

HtmlForm Control

10/23/2006

2 minutes to read

In this article

Creates a server-side control that maps to the

HTML element and allows you to create a container for elements in a Web page.

method=POST | GET

action="srcpageURL"

runat="server" >

Other controls, input forms, and so on.

Remarks

Use the HtmlForm control to program against the HTML

element. To take advantage of the postback services, all Web Forms controls, whether HTML, Web, pagelet, or custom, 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. The element will either 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 post back services provided by the Web Forms.

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.

Example

The following example shows three HtmlButton controls with a separate OnServerClick handler for each button. Each of these events causes a post back to the server (the HtmlForm control is required for any scenario in which a post back 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.

Sub Button1_OnClick(Source As Object, e As EventArgs)

Span1.InnerHtml = "You clicked Button1"

End Sub

Sub Button2_OnClick(Source As Object, e As EventArgs)

Span2.InnerHtml = "You clicked Button2"

End Sub

Sub Button3_OnClick(Source As Object, e As EventArgs)

Span3.InnerHtml = "You clicked Button3"

End Sub

HtmlForm Sample

OnServerClick="Button1_OnClick">

Button1

OnServerClick="Button2_OnClick">

Button2

OnServerClick="Button3_OnClick">

Button3

[C#]

void Button1_OnClick(object Source, EventArgs e)

{

Span1.InnerHtml="You clicked Button1";

}

void Button2_OnClick(object Source, EventArgs e)

{

Span2.InnerHtml="You clicked Button2";

}

void Button3_OnClick(object Source, EventArgs e)

{

Span3.InnerHtml="You clicked Button3";

}

HtmlForm Sample

OnServerClick="Button1_OnClick">

Button1

OnServerClick="Button2_OnClick">

Button2

OnServerClick="Button3_OnClick">

Button3

See Also

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值