ImageButton.AddAttributesToRender(HtmlTextWriter) Método
Definição
Adiciona os atributos de um ImageButton ao fluxo de saída para renderização no cliente.Adds the attributes of an ImageButton to the output stream for rendering on the client.
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
O fluxo de saída a renderizar no cliente.The output stream to render on the client.
Exemplos
O exemplo de código a seguir demonstra como substituir o AddAttributesToRender método em um controle de servidor personalizado para que o ImageButton texto sempre apareça com uma borda fina.The following code example demonstrates how to override the AddAttributesToRender method in a custom server control so that the ImageButton text always appears with a thin border.
Observação
O exemplo de código a seguir usa o modelo de código de arquivo único e pode não funcionar corretamente se copiado diretamente para um arquivo code-behind.The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. A primeira parte deste exemplo de código deve ser copiada em um arquivo de texto vazio que tenha uma extensão. aspx.The first part of this code sample must be copied into an empty text file that has an .aspx extension. A segunda parte deve ser salva como um arquivo de código (. cs para C# ou. vb para Visual Basic).The second part must be saved as a code file (either .cs for C# or .vb for Visual Basic). Para obter mais informações sobre o modelo de código Web Forms, consulte modelo de código de página do ASP.NET Web Forms.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"
"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
Comentários
O OnPreRender método é usado principalmente pelos desenvolvedores de controle ao derivar uma classe personalizada do ImageButton controle.The OnPreRender method is used primarily by control developers when deriving a custom class from the ImageButton control.