Button.AddAttributesToRender(HtmlTextWriter) Metoda
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Dodaje atrybuty Button kontrolki do strumienia wyjściowego do renderowania na kliencie.
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)
Parametry
- writer
- HtmlTextWriter
Element HtmlTextWriter zawierający strumień wyjściowy do renderowania na kliencie.
Przykłady
W poniższym przykładzie kodu pokazano, jak zastąpić AddAttributesToRender metodę w niestandardowej kontrolce serwera, tak aby Button tekst był zawsze wyświetlany na czerwono.
<%@ Page language="c#" %>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS" %>
<!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 Button - AddAttributesToRender - C# Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom Button - AddAttributesToRender - C# Example</h3>
<aspSample:CustomButtonAddAttributesToRender
id="Button1"
runat="server"
Text="Button" />
</form>
</body>
</html>
<%@ 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"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Custom Button - AddAttributesToRender - VB.NET Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom Button - AddAttributesToRender - VB.NET Example</h3>
<aspSample:CustomButtonAddAttributesToRender id="Button1" runat="server" Text="Button" />
</form>
</body>
</html>
using System.Web;
using System.Security.Permissions;
namespace Samples.AspNet.CS.Controls
{
[AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class CustomButtonAddAttributesToRender : System.Web.UI.WebControls.Button
{
protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
{
// 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
base.AddAttributesToRender(writer);
}
}
}
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
MyBase.AddAttributesToRender(writer)
End Sub
End Class
End Namespace ' Samples.AspNet