ImageButton.TagKey 属性

定义

获取与 HtmlTextWriterTag 控件相对应的 ImageButton 值。

protected:
 virtual property System::Web::UI::HtmlTextWriterTag TagKey { System::Web::UI::HtmlTextWriterTag get(); };
[System.ComponentModel.Browsable(false)]
protected override System.Web.UI.HtmlTextWriterTag TagKey { get; }
[<System.ComponentModel.Browsable(false)>]
member this.TagKey : System.Web.UI.HtmlTextWriterTag
Protected Overrides ReadOnly Property TagKey As HtmlTextWriterTag

属性值

一个 HtmlTextWriterTag 枚举值。

属性

示例

下面的代码示例演示如何重写 TagKey 自定义 ImageButton 控件中的 方法,使其始终返回 Input 标记。

注意

下面的代码示例使用单文件代码模型,如果直接复制到代码隐藏文件中,可能无法正常工作。 必须将代码示例的第一部分复制到扩展名为 .aspx 的空文本文件中。 第二个部分必须位于用于 C#) 的 .cs 文件 (中,或位于 Visual Basic) (的 .vb 文件中。 有关Web Forms代码模型的详细信息,请参阅 ASP.NET Web Forms页代码模型

<%@ 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 ImageButton - TagKey - C# Example</title>
    <script runat="server">
      void ImageButton1_Command(Object sender, CommandEventArgs e) 
      {
        // Redirect to the Microsoft home page.
        Response.Redirect("http://www.microsoft.com/");
      }
    </script>
    </head>
    <body>
        <form id="Form1" method="post" runat="server">
            <h3>Custom ImageButton - TagKey - C# Example</h3>
            
            <aspSample:CustomImageButtonTagKey 
              id="ImageButton1" 
              runat="server" 
              OnCommand="ImageButton1_Command" 
              AlternateText="Microsoft Home" 
              ImageUrl="http://www.microsoft.com/homepage/gif/bnr-microsoft.gif" />

        </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 ImageButton - TagKey - VB.NET Example</title>
        <script runat="server">
            Sub ImageButton1_Command(sender As Object, e As CommandEventArgs)
                ' Redirect to the Microsoft home page.
                Response.Redirect("http://www.microsoft.com/")
            End Sub
        </script>
    </head>
    <body>
        <form id="Form1" method="post" runat="server">
            <h3>Custom ImageButton - TagKey - VB.NET Example</h3>
            
            <aspSample:CustomImageButtonTagKey id="ImageButton1" runat="server" 
             OnCommand="ImageButton1_Command" AlternateText="Microsoft Home" 
             ImageUrl="http://www.microsoft.com/homepage/gif/bnr-microsoft.gif" />

        </form>
    </body>
</html>
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
        {
            get
            {
            // Specify that only the Input HTML tag can be passed to the HtmlTextWriter.
            return System.Web.UI.HtmlTextWriterTag.Input;
            }
        }
    }
}
<AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class CustomImageButtonTagKey
    Inherits System.Web.UI.WebControls.ImageButton

    Protected Overrides ReadOnly Property TagKey() As System.Web.UI.HtmlTextWriterTag
        Get
            ' Specify that only the Input HTML tag can be passed to the HtmlTextWriter.
            Return System.Web.UI.HtmlTextWriterTag.Input
        End Get
    End Property
End Class

注解

TagKey 控件派生自定义类 ImageButton 时,控件开发人员主要使用 属性。

TagKey使用 属性确定与HtmlTextWriterTag控件ImageButton关联的值。 此属性重写基实现,以始终返回 HtmlTextWriterTag.Input

适用于

另请参阅