AttributeCollection.Render(HtmlTextWriter) Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee schrijft u de verzameling kenmerken naar de opgegeven HtmlTextWriter uitvoerstroom voor het besturingselement waartoe de verzameling behoort.
public:
void Render(System::Web::UI::HtmlTextWriter ^ writer);
public void Render(System.Web.UI.HtmlTextWriter writer);
member this.Render : System.Web.UI.HtmlTextWriter -> unit
Public Sub Render (writer As HtmlTextWriter)
Parameters
- writer
- HtmlTextWriter
Een HtmlTextWriter exemplaar dat de kenmerkverzameling naar de huidige uitvoerstroom schrijft.
Voorbeelden
Deze sectie bevat twee codevoorbeelden. In het eerste codevoorbeeld ziet u hoe u van de WebControl klasse kunt overnemen om een aangepast besturingselement te maken met de naam AttribRender waarmee de Render methode wordt overschreven. In het tweede codevoorbeeld ziet u hoe u het aangepaste besturingselement gebruikt in een ASP.NET webpagina.
In het volgende voorbeeld ziet u hoe u een aangepast besturingselement maakt dat AttribRender de Render methode van de WebControl klasse overschrijft zonder de Render methode van de basisklasse aan te roepen. Roept in plaats daarvan AttribRender de Render methode aan.
/* 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.
[AspNetHostingPermission(SecurityAction.Demand,
Level=AspNetHostingPermissionLevel.Minimal)]
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.
Attributes.Render(output);
}
}
}
' 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.
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports 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.
<AspNetHostingPermission(SecurityAction.Demand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class AttribRender
Inherits WebControl
' This is the overridden WebControl.Render method.
Protected Overrides Sub Render(ByVal output As HtmlTextWriter)
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.
Attributes.Render(output)
End Sub
End Class
End Namespace 'AC_Render
In het volgende voorbeeld ziet u hoe u het AttribRender aangepaste besturingselement op een webpagina gebruikt. Hierbij wordt ervan uitgegaan dat het codebestand voor het aangepaste besturingselement zich in de map App_Code voor de toepassing bevindt.
<%@ 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.");
Place1.Controls.Add(c);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>AttributeCollection Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:PlaceHolder id="Place1" runat="server"></asp:PlaceHolder>
</div>
</form>
</body>
</html>
<%@ Page Language="VB"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim c As New AC_Render.AttribRender()
c.Attributes.Add("Text", "Hello World!")
c.Attributes.Add("Attribute1", "The value for Attribute1.")
Place1.Controls.Add(c)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>AttributeCollection Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:PlaceHolder id="Place1" runat="server"></asp:PlaceHolder>
</div>
</form>
</body>
</html>