Page.RegisterRequiresRaiseEvent(IPostBackEventHandler) Page.RegisterRequiresRaiseEvent(IPostBackEventHandler) Page.RegisterRequiresRaiseEvent(IPostBackEventHandler) Page.RegisterRequiresRaiseEvent(IPostBackEventHandler) Method


將 ASP.NET 伺服器控制項註冊為,在 Page 物件上處理控制項時,要求引發事件的控制項。Registers an ASP.NET server control as one requiring an event to be raised when the control is processed on the Page object.

 virtual void RegisterRequiresRaiseEvent(System::Web::UI::IPostBackEventHandler ^ control);
public virtual void RegisterRequiresRaiseEvent (System.Web.UI.IPostBackEventHandler control);
abstract member RegisterRequiresRaiseEvent : System.Web.UI.IPostBackEventHandler -> unit
override this.RegisterRequiresRaiseEvent : System.Web.UI.IPostBackEventHandler -> unit
Public Overridable Sub RegisterRequiresRaiseEvent (control As IPostBackEventHandler)


IPostBackEventHandler IPostBackEventHandler IPostBackEventHandler IPostBackEventHandler

要登錄的控制項。The control to register.


下列程式碼範例會使用RegisterRequiresRaiseEvent方法,以註冊ButtonWeb 伺服器控制項,為需要引發事件。The following code example uses the RegisterRequiresRaiseEvent method to register a Button Web server control as requiring an event to be raised. 註冊第一個之後Button控制項,您可能會造成第二個Button張貼的第一個按鈕的結果程式碼中宣告的控制項 click 至頁面的事件。After you have registered the first Button control, you can cause the second Button control declared in the code to post the results of the first button's click event to the page.

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.
  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
End Sub


只有一部伺服器控制項註冊每個頁面要求。Only one server control can be registered per page request. RegisterRequiresRaiseEvent控制項不包含其識別碼在表單中的回傳資料的控制項時,必須使用。The RegisterRequiresRaiseEvent must be used when the control does not include its control ID in the form post data. 此外,已註冊的控制項必須實作IPostBackEventHandler介面。Also, the control that is registered must implement the IPostBackEventHandler interface.