TextBox.TagKey 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得文字方塊控制項的 HTML 標記。 這個屬性受到保護。
protected:
virtual property System::Web::UI::HtmlTextWriterTag TagKey { System::Web::UI::HtmlTextWriterTag get(); };
protected override System.Web.UI.HtmlTextWriterTag TagKey { get; }
member this.TagKey : System.Web.UI.HtmlTextWriterTag
Protected Overrides ReadOnly Property TagKey As HtmlTextWriterTag
屬性值
如果文字方塊為多行,則為 Textarea,否則為 Input。
範例
下列程式代碼範例示範如何使用 TagKey 屬性來建立自定義文字框。
重要
這個範例有一個可接受使用者輸入的文字方塊,這可能會造成安全性威脅。 根據預設,ASP.NET Web 網頁會驗證使用者輸入未包含指令碼或 HTML 項目。 如需詳細資訊,請參閱 Script Exploits Overview (指令碼攻擊概觀)。
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS" %>
<%@ 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">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Custom TextBox - TagKey - C# Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom TextBox - TagKey - C# Example</h3>
<aspSample:CustomTextBoxTagKey
id="TextBox1"
runat="server">Hello World!
</aspSample:CustomTextBoxTagKey>
</form>
</body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB" %>
<%@ 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">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Custom TextBox - TagKey - VB.NET Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom TextBox - TagKey - VB.NET Example</h3>
<aspSample:CustomTextBoxTagKey
id="TextBox1"
runat="server">Hello World!
</aspSample:CustomTextBoxTagKey>
</form>
</body>
</html>
using System.Web;
using System.Security.Permissions;
namespace Samples.AspNet.CS.Controls
{
[AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
public sealed class CustomTextBoxTagKey : System.Web.UI.WebControls.TextBox
{
protected override System.Web.UI.HtmlTextWriterTag TagKey
{
get
{
// If the TextMode is MultiLine, return a Textarea tag,
// else return an Input tag.
if (this.TextMode == System.Web.UI.WebControls.TextBoxMode.MultiLine)
{
return System.Web.UI.HtmlTextWriterTag.Textarea;
}
else
{
return System.Web.UI.HtmlTextWriterTag.Input;
}
}
}
}
}
Imports System.Web
Imports System.Security.Permissions
Namespace Samples.AspNet.VB.Controls
<AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class CustomTextBoxTagKey
Inherits System.Web.UI.WebControls.TextBox
Protected Overrides ReadOnly Property TagKey() As System.Web.UI.HtmlTextWriterTag
Get
' If the TextMode is MultiLine, return a Textarea tag, else return an Input tag.
If Me.TextMode = System.Web.UI.WebControls.TextBoxMode.MultiLine Then
Return System.Web.UI.HtmlTextWriterTag.Textarea
Else
Return System.Web.UI.HtmlTextWriterTag.Input
End If
End Get
End Property
End Class
End Namespace