HtmlForm 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 HtmlForm 類別的新執行個體。
public:
HtmlForm();
public HtmlForm ();
Public Sub New ()
範例
下列程式碼範例示範如何建立 控制項的新實例 HtmlForm ,並將其放在網頁上。
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server" >
void Page_Load(Object sender, EventArgs e)
{
// Create a new HtmlForm control.
HtmlForm form = new HtmlForm();
form.ID = "ButtonForm";
// Create an HtmlButton control.
HtmlButton button = new HtmlButton();
button.InnerHtml = "Click Me";
// Register the event-handling method for the ServerClick event of the
// HtmlButton control.
button.ServerClick += new System.EventHandler(this.Button_Click);
// Add the HtmlButton control to the HtmlForm control.
form.Controls.Add(button);
// Add the HtmlForm control to the control collection of the page.
Page.Controls.Add(form);
}
void Button_Click(Object sender, EventArgs e)
{
// Write a message to the user.
Message.InnerHtml = "Hello World";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>HtmlForm Constructor Example</title>
</head>
<body>
<h3> HtmlForm Constructor Example </h3>
<span id="Message" runat="server"/>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server" >
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Create a new HtmlForm control.
Dim form As HtmlForm = New HtmlForm()
form.ID = "ButtonForm"
' Create an HtmlButton control.
Dim button As HtmlButton = New HtmlButton()
button.InnerHtml = "Click Me"
' Register the event-handling method for the ServerClick event of the
' HtmlButton control.
AddHandler button.ServerClick, AddressOf Button_Click
' Add the HtmlButton control to the HtmlForm control.
form.Controls.Add(button)
' Add the HtmlForm to the control collection of the page.
Page.Controls.Add(form)
End Sub
Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs)
' Write a message to the user.
Message.InnerHtml = "Hello World"
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>HtmlForm Constructor Example</title>
</head>
<body>
<h3> HtmlForm Constructor Example </h3>
<span id="Message" runat="server"/>
</body>
</html>
備註
使用此建構函式來建立和初始化 類別的新實例 HtmlForm 。
下表顯示 實例 HtmlForm 的初始屬性值。
屬性 | 初始值 |
---|---|
TagName | 「form」 常值字串。 |