HtmlInputControl.Type 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
得到一種類型的 HtmlInputControl。
public:
property System::String ^ Type { System::String ^ get(); };
public string Type { get; }
member this.Type : string
Public ReadOnly Property Type As String
屬性值
包含 型 HtmlInputControl別的字串。
範例
以下程式碼範例示範如何利用屬性 Type 來判斷被點擊的類型 HtmlInputControl 。
<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title> HtmlInputControl Type Example </title>
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
// Create the data source.
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add(new DataColumn("Value", typeof(string)));
for (int i = 0; i < 3; i++)
{
dr = dt.NewRow();
dr[0] = "Item " + i.ToString();
dt.Rows.Add(dr);
}
// Bind the data source to the Repeater control.
Repeater1.DataSource = new DataView(dt);
Repeater1.DataBind();
}
void AddButton_Click(Object sender, EventArgs e)
{
Message.Text = "The type of the HtmlInputControl clicked is " +
((HtmlInputControl)sender).Type;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3> HtmlInputControl Type Example </h3>
<asp:Repeater id="Repeater1"
runat="server">
<ItemTemplate>
<input type="submit"
name="AddButton"
value='<%# DataBinder.Eval(Container.DataItem, "Value") %>'
onserverclick="AddButton_Click"
runat="server"/>
</ItemTemplate>
</asp:Repeater>
<br /><br />
<asp:Label id="Message" runat="server"/>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title> HtmlInputControl Type Example </title>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
' Create the data source.
Dim dt As DataTable = New DataTable()
Dim dr As DataRow
dt.Columns.Add(new DataColumn("Value", GetType(String)))
Dim i As Integer
For i = 0 to 2
dr = dt.NewRow()
dr(0) = "Item " + i.ToString()
dt.Rows.Add(dr)
Next i
' Bind the data source to the Repeater control.
Repeater1.DataSource = New DataView(dt)
Repeater1.DataBind()
End Sub
Sub AddButton_Click(sender As Object, e As EventArgs)
Message.Text = "The type of the HtmlInputControl clicked is " & _
CType(sender, HtmlInputControl).Type
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<h3> HtmlInputControl Type Example </h3>
<asp:Repeater id="Repeater1"
runat="server">
<ItemTemplate>
<input id="Submit1" type="submit"
name="AddButton"
value='<%# DataBinder.Eval(Container.DataItem, "Value") %>'
onserverclick="AddButton_Click"
runat="server"/>
</ItemTemplate>
</asp:Repeater>
<br /><br />
<asp:Label id="Message" runat="server"/>
</form>
</body>
</html>
備註
使用此性質,取得 HtmlInputControl.
下表展示了該 Type 性質的不同可能值。
| 價值 | 說明 |
|---|---|
| 收發簡訊 | 一個用於資料輸入的文字框。 |
| 密碼 | 一個遮蔽使用者輸入的文字框。 |
| 勾選框 | 一個勾選框,表示真或假條件。 |
| radio | 一個表示從互斥的一組選擇的單選按鈕。 |
| 按鈕 | 一個指令鍵。 |
| 提交 | 一個按鈕,將表單提交給伺服器。 |
| 重置 | 一個可以清除表單的按鈕。 |
| 檔案 | 一個可以上傳檔案的按鈕。 |
| 隱藏 | 網頁上的一個非顯示欄位,用於在貼文間持久化資訊至伺服器。 |
| 圖片 | 一個圖片按鈕。 |