ImageButton.OnPreRender(EventArgs) Méthode

Définition

Détermine si un clic a été effectué sur l'image avant son affichage sur le client.

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’elle affiche toujours une bordure fine dans un contrôle serveur personnalisé ImageButton .

Notes

L’exemple de code suivant utilise le modèle de code à fichier unique et peut ne pas fonctionner correctement s’il est copié directement dans un fichier code-behind. La première partie de l’exemple de code doit être copiée dans un fichier texte vide qui a une extension .aspx. La deuxième partie doit se trouver dans un fichier .cs (pour C#) ou un fichier .vb (pour Visual Basic). Pour plus d’informations sur le modèle de code Web Forms, consultez ASP.NET Web Forms Modèle de code de page.

<%@ 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 ImageButton - OnPreRender - C# Example</title>
    <script runat="server">
      void ImageButton1_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 ImageButton - OnPreRender - C# Example</h3>
            
            <aspSample:CustomImageButtonOnPreRender 
              id="ImageButton1" 
              runat="server" 
              OnCommand="ImageButton1_Command" 
              AlternateText="Microsoft Home" 
              ImageUrl="http://www.microsoft.com/homepage/gif/bnr-microsoft.gif" />

        </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 ImageButton - OnPreRender - VB.NET Example</title>
        <script runat="server">
            Sub ImageButton1_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 ImageButton - OnPreRender - VB.NET Example</h3>
            
            <aspSample:CustomImageButtonOnPreRender id="ImageButton1" runat="server" 
             OnCommand="ImageButton1_Command" AlternateText="Microsoft Home" 
             ImageUrl="http://www.microsoft.com/homepage/gif/bnr-microsoft.gif" />

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

namespace Samples.AspNet.CS.Controls
{
    [AspNetHostingPermission(SecurityAction.Demand, 
        Level = AspNetHostingPermissionLevel.Minimal)]
    public class CustomImageButtonOnPreRender : ImageButton
    {
        protected override void OnPreRender(EventArgs e)
        {
            // Run the OnPreRender method on the base class.
            base.OnPreRender(e);

            // Always display the ImageButton with a thin border.
            this.BorderWidth =  Unit.Point(1);
        }
    }
}
<AspNetHostingPermission(SecurityAction.Demand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class CustomImageButtonOnPreRender
    Inherits ImageButton

    Protected Overrides Sub OnPreRender(ByVal e As EventArgs)

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

        ' Always display the ImageButton with a thin border.
        Me.BorderWidth = Unit.Point(1)
    End Sub
End Class

Remarques

La OnPreRender méthode est principalement utilisée par les développeurs de contrôles lors de la dérivation d’une classe personnalisée à partir du ImageButton contrôle .

S’applique à

Voir aussi