共用方式為


Page.RaisePostBackEvent(IPostBackEventHandler, String) 方法

定義

告知造成回傳的伺服器控制項,應該處理收到的回傳事件。

protected:
 virtual void RaisePostBackEvent(System::Web::UI::IPostBackEventHandler ^ sourceControl, System::String ^ eventArgument);
protected virtual void RaisePostBackEvent (System.Web.UI.IPostBackEventHandler sourceControl, string eventArgument);
abstract member RaisePostBackEvent : System.Web.UI.IPostBackEventHandler * string -> unit
override this.RaisePostBackEvent : System.Web.UI.IPostBackEventHandler * string -> unit
Protected Overridable Sub RaisePostBackEvent (sourceControl As IPostBackEventHandler, eventArgument As String)

參數

sourceControl
IPostBackEventHandler

造成回傳的 ASP.NET 伺服器控制項。 這個控制項必須實作 IPostBackEventHandler 介面。

eventArgument
String

回傳引數。

範例

下列範例會 RaisePostBackEvent 使用 方法來通知 ASP.NET 按兩下自定義 userButton 伺服器控制時引發回傳事件。

void DisplayUserName(Object sender, EventArgs ea) 
{
   Response.Write("Welcome to " + Server.HtmlEncode(userName.Text));
}
void RaiseEvent(Object sender, EventArgs ea)
{
   // Raise a post back event for a control.
   this.RaisePostBackEvent(userButton, "");
}
void Page_Load(Object sender, EventArgs ea)
{
   // Register a control as one that requires postback handling.
   this.RegisterRequiresRaiseEvent(userButton);
}
    Sub DisplayUserName(Sender As Object, e As EventArgs) 
       Response.Write("Welcome to " + Server.HtmlEncode(userName.Text))
    End Sub

   Sub MyRaiseEvent(Sender As Object, e As EventArgs)
       'Raises a post back event for a control.
        Me.RaisePostBackEvent(userButton, "")
   End Sub 
    
    Sub Page_Load(Sender As Object, e As EventArgs)

      'Registers a control as one that requires postback handling
      Me.RegisterRequiresRaiseEvent(userButton)
  End Sub

備註

物件 Page 會在回傳發生時呼叫 RaisePostBackEvent 方法。 載入和變更通知完成之後,就會在頁面生命週期中發生此呼叫,但在預先呈現之前發生。

適用於

另請參閱