共用方式為


IPostBackEventHandler.RaisePostBackEvent(String) 方法

定義

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

public:
 void RaisePostBackEvent(System::String ^ eventArgument);
public void RaisePostBackEvent (string eventArgument);
abstract member RaisePostBackEvent : string -> unit
Public Sub RaisePostBackEvent (eventArgument As String)

參數

eventArgument
String

String,代表傳遞至事件處理常式的選擇性事件引數。

範例

下列程式代碼範例會定義造成回傳的自定義按鈕伺服器控件、使用 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

備註

頁面會將 參數的值 eventArgument 傳遞至 RaisePostBackEvent 實作 IPostBackEventHandler 介面之控件的方法。 這個控件也會轉譯導致回傳發生的 HTML 專案。 如果控件轉譯回回的用戶端腳本,則會在 參數中 eventArgument 傳遞來自腳本的自變數。 如果回傳是由簡單的提交作業所造成,則 eventArgument 參數為 null

這個方法提供 HTML 和 Web 伺服器控制項所實作之許多事件的功能。

適用於

另請參閱