IPostBackEventHandler Interface

Définition

Définit la méthode que les contrôles serveur ASP.NET doivent implémenter pour gérer les événements de publication.

public interface class IPostBackEventHandler
public interface IPostBackEventHandler
type IPostBackEventHandler = interface
Public Interface IPostBackEventHandler
Dérivé

Exemples

L’exemple de code suivant définit un contrôle serveur de bouton personnalisé qui provoque la publication, capture l’événement de publication à l’aide de la RaisePostBackEvent méthode et déclenche un Click événement sur le serveur.

using System;
using System.Web.UI;
using System.Collections;
using System.Collections.Specialized;

namespace CustomControls {

   [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
   public class MyButton: Control, IPostBackEventHandler {

      // Defines the Click event.
      public event EventHandler Click;

      //Invoke delegates registered with the Click event.
      protected virtual void OnClick(EventArgs e) {

         if (Click != null) {
            Click(this, e);
         }
      }

      // Define the method of IPostBackEventHandler that raises change events.
      public void RaisePostBackEvent(string eventArgument){

         OnClick(new EventArgs());
      }

      protected override void Render(HtmlTextWriter output) {
         output.Write("<INPUT TYPE = submit name = " + this.UniqueID +
            " Value = 'Click Me' />");
      }
   }
}
Imports System.Web.UI
Imports System.Collections
Imports System.Collections.Specialized

Namespace CustomControls    
    
    <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> Public Class MyButton
        Inherits Control
        Implements IPostBackEventHandler
        
        ' Define the Click event.
        Public Event Click As EventHandler
        
        
        ' Invoke delegates registered with the Click event.
        Protected Overridable Sub OnClick(e As EventArgs)            
            RaiseEvent Click(Me, e)
        End Sub
        
        
        ' Define the method of IPostBackEventHandler that raises change events.
        Public Sub RaisePostBackEvent(eventArgument As String) _
        Implements IPostBackEventHandler.RaisePostBackEvent
        
            OnClick(New EventArgs())
        End Sub       
        
        
        Protected Overrides Sub Render(output As HtmlTextWriter)
            output.Write("<INPUT TYPE = submit name = " & Me.UniqueID & _
                " Value = 'Click Me' />")
        End Sub
        
    End Class
End Namespace

Remarques

Pour créer un contrôle serveur qui capture les informations de soumission de formulaire à partir du navigateur, vous devez implémenter cette interface. Pour plus d’informations sur l’utilisation de cette interface, consultez Gestion des événements de serveur dans ASP.NET Web Forms Pages.

Méthodes

RaisePostBackEvent(String)

Implémenté par une classe, permet à un contrôle serveur de traiter un événement déclenché lorsqu'un formulaire est publié sur le serveur.

S’applique à

Voir aussi