Condividi tramite


Literal.Render(HtmlTextWriter) Metodo

Definizione

Invia il contenuto del controllo server a un oggetto HtmlTextWriter specificato che scrive il contenuto di cui eseguire il rendering nel client.

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)

Parametri

outputwriter
HtmlTextWriter

Oggetto HtmlTextWriter che riceve il contenuto del controllo server.

Esempio

Nell'esempio di codice seguente viene illustrato come eseguire l'override del Render metodo in un controllo server personalizzato in modo che il testo specifico venga sempre visualizzato prima dell'oggetto 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

Si applica a