IPostBackEventHandler Interface


定义 ASP.NET 服务器控件为处理回发事件而必须实现的方法。Defines the method ASP.NET server controls must implement to handle postback events.

public interface class IPostBackEventHandler
public interface IPostBackEventHandler
type IPostBackEventHandler = interface
Public Interface IPostBackEventHandler


下面的代码示例定义了一个自定义按钮服务器控件,该控件将导致回发,使用 RaisePostBackEvent 方法捕获回发事件,并在服务器上引发 Click 事件。The following code example defines a custom button server control that causes postback, captures the postback event using the RaisePostBackEvent method, and raises a Click event on the server.

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


若要创建从浏览器捕获窗体提交信息的服务器控件,您必须实现此接口。To create a server control that captures form submission information from the browser, you must implement this interface. 有关如何使用此接口的详细信息,请参阅ASP.NET Web Forms Pages 中的服务器事件处理For more information on how to use this interface, see Server Event Handling in ASP.NET Web Forms Pages.



当由类实现时,使服务器控件能够处理将窗体发送到服务器时引发的事件。When implemented by a class, enables a server control to process an event raised when a form is posted to the server.

Applies to

See also