Button.AddAttributesToRender Method (HtmlTextWriter)


This API supports the product infrastructure and is not intended to be used directly from your code.

Adds the attributes of the Button control to the output stream for rendering on the client.

Namespace:   System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

Protected Overrides Sub AddAttributesToRender (
	writer As HtmlTextWriter


Type: System.Web.UI.HtmlTextWriter

An System.Web.UI.HtmlTextWriter that contains the output stream to render on the client.

The following code example demonstrates how to override the AddAttributesToRender method in a custom server control, so that the Button text always displays in red.

<%@ Page language="VB" %>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" >
    <title>Custom Button - AddAttributesToRender - VB.NET Example</title>
    <form id="Form1" method="post" runat="server">
      <h3>Custom Button - AddAttributesToRender - VB.NET Example</h3>
      <aspSample:CustomButtonAddAttributesToRender id="Button1" runat="server" Text="Button" />
Imports System.Web
Imports System.Security.Permissions

Namespace Samples.AspNet.VB.Controls
    <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public NotInheritable Class CustomButtonAddAttributesToRender
        Inherits System.Web.UI.WebControls.Button

        Protected Overrides Sub AddAttributesToRender(ByVal writer As System.Web.UI.HtmlTextWriter)
            ' Add a client-side onclick event to the button.
            writer.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Onclick, "alert('Hello World');")

            ' Update the text of the button to be shown in the color Red
            writer.AddStyleAttribute(System.Web.UI.HtmlTextWriterStyle.Color, "Red")

            ' Call the base's AddAttributesToRender method
        End Sub
    End Class
End Namespace ' Samples.AspNet

.NET Framework
Available since 1.1
Return to top