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. Вторая часть должна находиться в CS-файле (для C#) или VB-файле (для Visual Basic). Дополнительные сведения о модели кода веб-формы см. в разделе Модель кода страницы 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.

Применяется к

См. также раздел