LinkButton.OnPreRender(EventArgs) Méthode

Définition

Déclenche l’événement PreRender.

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

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

Exemples

L’exemple de code suivant montre comment remplacer la OnPreRender méthode afin qu’une bordure ne soit jamais affichée dans un contrôle personnalisé LinkButton .

<%@ 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 LinkButton - OnPreRender - C# Example</title>
    <script runat="server">
      void LinkButton1_Command(Object sender, CommandEventArgs e) 
      {
        // Redirect to the Microsoft home page.
        Response.Redirect("http://www.microsoft.com/");
      }
    </script>
    </head>
    <body>
        <form id="Form1" method="post" runat="server">
            <h3>Custom LinkButton - OnPreRender - C# Example</h3>
            
            <aspSample:CustomLinkButtonOnPreRender 
              id="LinkButton1" 
              runat="server" 
              OnCommand="LinkButton1_Command" 
              ToolTip="Microsoft Home">Microsoft Corp.
            </aspSample:CustomLinkButtonOnPreRender>
            
        </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 LinkButton - OnPreRender - VB.NET Example</title>
        <script runat="server">
            Sub LinkButton1_Command(sender As Object, e As CommandEventArgs)
                ' Redirect to the Microsoft home page.
                Response.Redirect("http://www.microsoft.com/")
            End Sub
        </script>
    </head>
    <body>
        <form id="Form1" method="post" runat="server">
            <h3>Custom LinkButton - OnPreRender - VB.NET Example</h3>
            
            <aspSample:CustomLinkButtonOnPreRender id="LinkButton1" 
             runat="server" OnCommand="LinkButton1_Command" 
             ToolTip="Microsoft Home">Microsoft Corp.</aspSample:CustomLinkButtonOnPreRender>

        </form>
    </body>
</html>
using System.Web;
using System.Security.Permissions;

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

      // Always display the LinkButton without a border.
      this.BorderWidth =  System.Web.UI.WebControls.Unit.Point(0);
    }
  }
}
<AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class CustomLinkButtonOnPreRender
    Inherits System.Web.UI.WebControls.LinkButton

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

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

        ' Always display the LinkButton without a border.
        Me.BorderWidth = System.Web.UI.WebControls.Unit.Point(0)
    End Sub
End Class

Remarques

La OnPreRender méthode avertit le LinkButton contrôle d’effectuer toutes les étapes de prédéfinissement nécessaires avant d’enregistrer l’état d’affichage et de rendre le contenu au client.

S’applique à

Voir aussi