TextBox.OnPreRender(EventArgs) Méthode

Définition

Enregistre le script client pour générer des événements de publication avant le rendu sur le client si AutoPostBack est true.

protected:
 override void OnPreRender(EventArgs ^ e);
protected public:
 override void OnPreRender(EventArgs ^ e);
protected override void OnPreRender (EventArgs e);
protected internal override void OnPreRender (EventArgs e);
override this.OnPreRender : EventArgs -> unit
Protected Overrides Sub OnPreRender (e As EventArgs)
Protected Friend Overrides Sub OnPreRender (e As EventArgs)

Paramètres

e
EventArgs

EventArgs qui contient les données d’événement.

Exemples

L’exemple de code suivant montre comment remplacer la OnPreRender méthode afin qu’elle affiche toujours une bordure à un point dans un contrôle serveur personnalisé TextBox .

Important

Cet exemple comprend une zone de texte qui accepte une entrée d'utilisateur, ce qui constitue une menace potentielle pour la sécurité. Par défaut, les pages web ASP.NET vérifient que l’entrée d’utilisateur n’inclut pas de script ou d’éléments HTML. Pour plus d’informations, consultez Vue d’ensemble des attaques de script.

<%@ 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 TextBox - OnPreRender - C# Example</title>
    </head>
    <body>
        <form id="Form1" method="post" runat="server">
            <h3>Custom TextBox - OnPreRender - C# Example</h3>
            
            <aspSample:CustomTextBoxOnPreRender 
              id="TextBox1" 
              runat="server">Hello World!
            </aspSample:CustomTextBoxOnPreRender>
            
        </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 TextBox - OnPreRender - VB.NET Example</title>
    </head>
    <body>
        <form id="Form1" method="post" runat="server">
            <h3>Custom TextBox - OnPreRender - VB.NET Example</h3>
            
            <aspSample:CustomTextBoxOnPreRender id="TextBox1" 
             runat="server">Hello World!</aspSample:CustomTextBoxOnPreRender>
        </form>
    </body>
</html>
using System.Web;
using System.Security.Permissions;

namespace Samples.AspNet.CS.Controls
{
  [AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
  public sealed class CustomTextBoxOnPreRender : System.Web.UI.WebControls.TextBox
  {
    protected override void OnPreRender(System.EventArgs e)
    {
      // Run the OnPreRender method on the base class.
      base.OnPreRender(e);

      // Display the TextBox with a 1 point border.
      this.BorderWidth = System.Web.UI.WebControls.Unit.Point(1);
    }
  }
}
Imports System.Web
Imports System.Security.Permissions

Namespace Samples.AspNet.VB.Controls
    <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public NotInheritable Class CustomTextBoxOnPreRender
        Inherits System.Web.UI.WebControls.TextBox

        Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)

            ' Run the OnPreRender method on the base class.
            MyBase.OnPreRender(e)

            ' Display the TextBox with a 1 point border.
            Me.BorderWidth = System.Web.UI.WebControls.Unit.Point(1)
        End Sub
    End Class
End Namespace

S’applique à