IPostBackEventHandler 接口

定义

定义 ASP.NET 服务器控件为处理回发事件而必须实现的方法。

public interface IPostBackEventHandler
派生

示例

下面的代码示例定义一个自定义按钮服务器控件,该控件会导致回发,使用 RaisePostBackEvent 方法捕获回发事件,并在服务器上引发 事件 Click

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' />");
      }
   }
}

注解

若要创建从浏览器捕获表单提交信息的服务器控件,必须实现此接口。 有关如何使用此接口的详细信息,请参阅 ASP.NET Web 窗体页中的服务器事件处理

方法

RaisePostBackEvent(String)

当由类实现时,使服务器控件能够处理将窗体发送到服务器时引发的事件。

适用于

产品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

另请参阅