Export (0) Print
Expand All

TextBox.TagKey Property

This member overrides WebControl.TagKey, and more complete documentation might be available in that topic.

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)

'Declaration
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.

Security noteSecurity 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"
    "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>
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

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft