Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

AttributeCollection.Render Method

Writes the collection of attributes to the specified HtmlTextWriter output stream for the control to which the collection belongs.

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

public void Render(
	HtmlTextWriter writer


Type: System.Web.UI.HtmlTextWriter

An HtmlTextWriter instance that writes the attribute collection to the current output stream.

This section contains two code examples. The first code example shows how to inherit from the WebControl class to create a custom control named AttribRender that overrides the Render method. The second code example shows how to use the custom control in an ASP.NET Web page.

The following example shows how to create a custom control named AttribRender that overrides the Render method of the WebControl class without calling the Render method of the base class. Instead, AttribRender invokes the Render method.

/* Create a custom WebControl class, named AttribRender, that overrides 
   the Render method to write two introductory strings. Then call the
   AttributeCollection.Render method, which allows the control to write the
   attribute values that are added to it when it is included in a page.

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Permissions;

// Create the namespace that contains the AttribRender and the 
// page that accesses it. 
namespace AC_Render
   // This is the custom WebControl class.
   public class AttribRender : WebControl
      // This is the overridden WebControl.Render method. 
      protected override void Render(HtmlTextWriter output)
         output.Write("<h2>An AttributeCollection.Render Method Example</h2>");
         output.Write("The attributes, and their values, added to the ctl1 control are <br><br>");
         // This is the AttributeCollection.Render method call. When the 
         // page that contains this control is requested, the 
         // attributes that the page adds, and their values, 
         // are rendered to the page.

The following example shows how to use the AttribRender custom control in a Web page. It assumes that the code file for the custom control is in the App_Code folder for the application.

<%@ Page Language="C#"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

  protected void Page_Load(object sender, EventArgs e)
    AC_Render.AttribRender c = new AC_Render.AttribRender();
    c.Attributes.Add("Text", "Hello World!");
    c.Attributes.Add("Attribute1", "The value for Attribute1.");


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>AttributeCollection Example</title>
    <form id="form1" runat="server">
      <asp:PlaceHolder id="Place1" runat="server"></asp:PlaceHolder>

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1
© 2015 Microsoft