Compartir a través de


Literal.Render(HtmlTextWriter) Método

Definición

Envía el contenido del control de servidor al objeto HtmlTextWriter proporcionado, que escribe el contenido que se representará en el cliente.

protected:
 override void Render(System::Web::UI::HtmlTextWriter ^ output);
protected public:
 override void Render(System::Web::UI::HtmlTextWriter ^ writer);
protected override void Render (System.Web.UI.HtmlTextWriter output);
protected internal override void Render (System.Web.UI.HtmlTextWriter writer);
override this.Render : System.Web.UI.HtmlTextWriter -> unit
override this.Render : System.Web.UI.HtmlTextWriter -> unit
Protected Overrides Sub Render (output As HtmlTextWriter)
Protected Friend Overrides Sub Render (writer As HtmlTextWriter)

Parámetros

outputwriter
HtmlTextWriter

Objeto HtmlTextWriter que recibe el contenido del control de servidor.

Ejemplos

En el ejemplo de código siguiente se muestra cómo invalidar el Render método en un control de servidor personalizado para que siempre se muestre texto específico antes de Literal.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS" %>
<%@ Page Language="C#" AutoEventWireup="True" %>
<!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 LiteralControl - Render - C# Example</title>
       <script runat="server">
      void Button1_Click(Object sender, EventArgs e)
      {
         Literal1.Text = "Welcome to ASP.NET!";
      }
   </script>
    </head>
    <body>
        <form id="Form1" method="post" runat="server">
            <h3>Custom LiteralControl - Render - C# Example</h3>
            
            <aspSample:CustomLiteralRender id="Literal1" 
              runat="server" />

      <br /><br />

      <asp:Button id="Button1"
        Text="Change"
        OnClick="Button1_Click"
        runat="server"/>
        </form>
    </body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB" %>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!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 LiteralControl - Render - VB.Net Example</title>
       <script runat="server">
      Sub Button1_Click(sender As Object, e As EventArgs)
      
         Literal1.Text = "Welcome to ASP.NET!"

      End Sub
   </script>
    </head>
    <body>
        <form id="Form1" method="post" runat="server">
            <h3>Custom LiteralControl - Render - VB.Net Example</h3>
            
            <aspSample:CustomLiteralRender id="Literal1" 
              runat="server" />

      <br /><br />

      <asp:Button id="Button1"
        Text="Change"
        OnClick="Button1_Click"
        runat="server"/>
        </form>
    </body>
</html>
using System.Web;
using System.Security.Permissions;

namespace Samples.AspNet.CS.Controls
{
  [AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
  public sealed class CustomLiteralRender : System.Web.UI.LiteralControl
  {
    protected override void Render(System.Web.UI.HtmlTextWriter writer)
    {
      // Write out some literal text.
      writer.Write("Literal Text: ");
      
      // Call the base Render method.
      base.Render(writer);
    }
  }
}
<AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class CustomLiteralRender
    Inherits System.Web.UI.WebControls.Literal

    Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)

        ' Write out some literal text.
        writer.Write("Literal Text: ")

        ' Call the base Render method.
        MyBase.Render(writer)
    End Sub
End Class

Se aplica a