Partager via


Table.AddAttributesToRender(HtmlTextWriter) Méthode

Définition

Ajoute des attributs et des styles HTML qui doivent être rendus au HtmlTextWriter spécifié.

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)

Paramètres

writer
HtmlTextWriter

Flux de sortie qui restitue le contenu HTML sur le client.

Exemples

L’exemple de code suivant montre comment remplacer la AddAttributesToRender méthode dans un contrôle serveur personnalisé pour ajouter un attribut au Table.

<%@ 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 id="Head2" runat="server">
    <title>Custom Table - AddAttributesToRender - C# Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <h3>Custom Table - AddAttributesToRender - C# Example</h3>

    <aspSample:CustomTableAddAttributesToRender 
        id="Table1" runat="server"
        GridLines="Both" CellPadding="4">
        <asp:TableRow>
            <asp:TableCell>Row 0, Col 0</asp:TableCell>
            <asp:TableCell>Row 0, Col 1</asp:TableCell>
        </asp:TableRow>
        <asp:TableRow>
            <asp:TableCell>Row 1, Col 0</asp:TableCell>
            <asp:TableCell>Row 1, Col 1</asp:TableCell>
        </asp:TableRow>
    </aspSample:CustomTableAddAttributesToRender>
      
    </div>
    </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 id="Head2" runat="server">
    <title>Custom Table - AddAttributesToRender - VB Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <h3>Custom Table - AddAttributesToRender - VB Example</h3>

    <aspSample:CustomTableAddAttributesToRender 
        id="Table1" runat="server"
        GridLines="Both" CellPadding="4">
        <asp:TableRow>
            <asp:TableCell>Row 0, Col 0</asp:TableCell>
            <asp:TableCell>Row 0, Col 1</asp:TableCell>
        </asp:TableRow>
        <asp:TableRow>
            <asp:TableCell>Row 1, Col 0</asp:TableCell>
            <asp:TableCell>Row 1, Col 1</asp:TableCell>
        </asp:TableRow>
    </aspSample:CustomTableAddAttributesToRender>
      
    </div>
    </form>
</body>
</html>
using System.Web;
using System.Security.Permissions;

namespace Samples.AspNet.CS.Controls
{
  [AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
  public sealed class CustomTableAddAttributesToRender : System.Web.UI.WebControls.Table
  {
    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');");

      // 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 CustomTableAddAttributesToRender
        Inherits System.Web.UI.WebControls.Table

        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');")

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

Remarques

Cette méthode est principalement utilisée par les développeurs de contrôles pour insérer les attributs et styles appropriés dans le flux de HtmlTextWriter sortie d’un Table contrôle. Cette méthode se substitue à WebControl.AddAttributesToRender.

S’applique à

Voir aussi