Share via


ImageButton.AddAttributesToRender(HtmlTextWriter) Método

Definición

Agrega los atributos de la clase ImageButton al flujo de salida para su representación en el cliente.

protected:
 override void AddAttributesToRender(System::Web::UI::HtmlTextWriter ^ writer);
protected override void AddAttributesToRender (System.Web.UI.HtmlTextWriter writer);
override this.AddAttributesToRender : System.Web.UI.HtmlTextWriter -> unit
Protected Overrides Sub AddAttributesToRender (writer As HtmlTextWriter)

Parámetros

writer
HtmlTextWriter

Flujo de salida que se va a representar en el cliente.

Ejemplos

En el ejemplo de código siguiente se muestra cómo invalidar el AddAttributesToRender método en un control de servidor personalizado para que el ImageButton texto siempre aparezca con un borde fino.

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 de este ejemplo de código debe copiarse en un archivo de texto vacío que tenga una extensión .aspx. La segunda parte debe guardarse como un archivo de código (ya sea .cs para C# o .vb para Visual Basic). Para obtener más información sobre el modelo de código de Web Forms, vea modelo de código de página 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 - AddAttributesToRender - 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 - AddAttributesToRender - C# Example</h3>
            
            <aspSample:CustomImageButtonAddAttributesToRender 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 - AddAttributesToRender - 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 - AddAttributesToRender - VB.NET Example</h3>
            
            <aspSample:CustomImageButtonAddAttributesToRender 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 CustomImageButtonAddAttributesToRender : System.Web.UI.WebControls.ImageButton
    {
        protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
        {
            // Show the ImageButton with a thin border.
            writer.AddStyleAttribute("border-width","thin");

            // Call the Base's AddAttributesToRender method.
            base.AddAttributesToRender(writer);
        }
    }
}
<AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class CustomImageButtonAddAttributesToRender
    Inherits System.Web.UI.WebControls.ImageButton

    Protected Overrides Sub AddAttributesToRender(ByVal writer As System.Web.UI.HtmlTextWriter)

        ' Show the ImageButton with a thin border.
        writer.AddStyleAttribute("border-width", "thin")

        ' Call the Base's AddAttributesToRender method.
        MyBase.AddAttributesToRender(writer)
    End Sub
End Class

Comentarios

El OnPreRender método se usa principalmente por los desarrolladores de controles al derivar una clase personalizada del ImageButton control .

Se aplica a

Consulte también