TextBox.TagKey Property

Use BaseTrue

Gets the HTML tag for the text box control. This property is protected.

Namespace:   System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

Protected Overrides ReadOnly Property TagKey As HtmlTextWriterTag

Property Value

Type: System.Web.UI.HtmlTextWriterTag

HtmlTextWriterTag.Textarea if the text box is multiline; otherwise, Input.

The following code example demonstrates how to use the TagKey property to create a custom text box.

System_CAPS_security Security Note

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.VB.Controls" Assembly="Samples.AspNet.VB" %>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" >
        <title>Custom TextBox - TagKey - VB.NET Example</title>
        <form id="Form1" method="post" runat="server">
            <h3>Custom TextBox - TagKey - VB.NET Example</h3>

              runat="server">Hello World!

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
                ' 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
                    Return System.Web.UI.HtmlTextWriterTag.Input
                End If
            End Get
        End Property
    End Class
End Namespace

.NET Framework
Available since 1.1
Return to top