ImageButton.TagKey Propiedad

Definición

Obtiene el valor de HtmlTextWriterTag correspondiente al control 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

Valor de propiedad

Valor de enumeración HtmlTextWriterTag.

Atributos

Ejemplos

En el ejemplo de código siguiente se muestra cómo invalidar el TagKey método en un control personalizado ImageButton para que siempre devuelva una etiqueta Input.

Nota

En el ejemplo de código siguiente se usa el modelo de código de un solo archivo y es posible que no funcione correctamente si se copia directamente en un archivo de código subyacente. La primera parte del ejemplo de código debe copiarse en un archivo de texto vacío que tenga una extensión .aspx. La segunda parte debe estar en un archivo .cs (para C#) o en un archivo .vb (para Visual Basic). Para obtener más información sobre el modelo de código de Web Forms, consulte ASP.NET Web Forms Modelo de código de página.

<%@ 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

Comentarios

La TagKey propiedad se usa principalmente por los desarrolladores de controles al derivar una clase personalizada del ImageButton control.

Utilice la TagKey propiedad para determinar el HtmlTextWriterTag valor asociado a un ImageButton control . Esta propiedad invalida la implementación base para devolver HtmlTextWriterTag.Inputsiempre .

Se aplica a

Consulte también