TextBox.TagKey Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the HTML tag for the text box control. This property is protected.
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
Property Value
Textarea if the text box is multiline; otherwise, Input.
Examples
The following code example demonstrates how to use the TagKey property to create a custom text box.
Important
This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see 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
Applies to
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기