ImageButton.TagKey Property


Gets the HtmlTextWriterTag value that corresponds to the ImageButton control.

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

protected override HtmlTextWriterTag TagKey { get; }

Property Value

Type: System.Web.UI.HtmlTextWriterTag

An HtmlTextWriterTag enumeration value.

The TagKey property is used primarily by control developers when deriving a custom class from the ImageButton control.

Use the TagKey property to determine the HtmlTextWriterTag value associated with an ImageButton control. This property overrides the base implementation to always return HtmlTextWriterTag.Input.

The following code example demonstrates how to override the TagKey method in a custom ImageButton control so that it always returns an Input tag.


The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. The first part of the code sample must be copied into an empty text file that has an .aspx extension. The second part must be in a .cs file (for C#) or a .vb file (for Visual Basic). For more information on the Web Forms code model, see ASP.NET Web Forms Page Code Model.

<%@ 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"
<html xmlns="" >
        <title>Custom ImageButton - TagKey - C# Example</title>
    <script runat="server">
      void ImageButton1_Command(Object sender, CommandEventArgs e) 
        // Redirect to the Microsoft home page.
        <form id="Form1" method="post" runat="server">
            <h3>Custom ImageButton - TagKey - C# Example</h3>

              AlternateText="Microsoft Home" 
              ImageUrl="" />

using System.Web;
using System.Security.Permissions;

namespace Samples.AspNet.CS.Controls
    [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
    public sealed class CustomImageButtonTagKey : System.Web.UI.WebControls.ImageButton
        protected override System.Web.UI.HtmlTextWriterTag TagKey
            // Specify that only the Input HTML tag can be passed to the HtmlTextWriter.
            return System.Web.UI.HtmlTextWriterTag.Input;

.NET Framework
Available since 1.1
Return to top