共用方式為


IPostBackEventHandler 介面

定義

定義 ASP.NET 伺服器控制項必須實作以處理回傳事件的方法。

public interface class IPostBackEventHandler
public interface IPostBackEventHandler
type IPostBackEventHandler = interface
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' />");
      }
   }
}
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

備註

若要建立伺服器控制項以從瀏覽器擷取表單提交資訊,您必須實作此介面。 如需如何使用這個介面的詳細資訊,請參閱 ASP.NET Web Forms Pages 中的伺服器事件處理

方法

RaisePostBackEvent(String)

當類別實作時,啟用伺服器控制項以處理表單張貼至伺服器時所引發的事件。

適用於

另請參閱