Page.RegisterRequiresPostBack(Control) Page.RegisterRequiresPostBack(Control) Page.RegisterRequiresPostBack(Control) Method


將控制項註冊為,當頁面回傳給伺服器時,需要回傳處理的控制項。Registers a control as one that requires postback handling when the page is posted back to the server.

 void RegisterRequiresPostBack(System::Web::UI::Control ^ control);
public void RegisterRequiresPostBack (System.Web.UI.Control control);
member this.RegisterRequiresPostBack : System.Web.UI.Control -> unit


Control Control Control

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


要註冊的控制項不會實作 IPostBackDataHandler 介面。The control to register does not implement the IPostBackDataHandler interface.


下列程式碼範例會使用RegisterRequiresPostBack方法來要求文字方塊控制項, myTextBox、 要張貼上一步,然後才能執行 文字 方塊相關聯的任何程式碼。The following code example uses the RegisterRequiresPostBack method to require a text box control, myTextBox, to be posted back before any code associated with the text box can execute. TextBox 控制項實作IPostBackDataHandler介面。TextBox controls implement the IPostBackDataHandler interface.


這個範例有一個可接受使用者輸入的文字方塊,這可能會造成安全性威脅。This example has a text box that accepts user input, which is a potential security threat. 根據預設,ASP.NET Web 網頁會驗證使用者輸入未包含指令碼或 HTML 項目。By default, ASP.NET Web pages validate that user input does not include script or HTML elements. 如需詳細資訊,請參閱 Script Exploits Overview (指令碼攻擊概觀)。For more information, see Script Exploits Overview.

protected void Text_Change(object sender, EventArgs e)
  myLabel.Text = "<b>Welcome " + myTextBox.Text + " to ASP.NET</b>";

protected void Page_PreRender(object sender, EventArgs e)
Sub Text_Change(ByVal sender As Object, ByVal e As EventArgs)
  myLabel.Text = "<b>Welcome " + myTextBox.Text + " to ASP.NET</b>"
End Sub 'Text_Change

Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub


要註冊的控制項必須實作IPostBackDataHandler介面或HttpException,就會引發。The control to be registered must implement the IPostBackDataHandler interface or an HttpException is raised. 由控制項,實作時IPostBackDataHandler的回傳資料處理和引發的任何文章的介面可讓備份資料已變更事件。When implemented by a control, the IPostBackDataHandler interface enables handling of post back data and raising of any post back data changed events. 如需有關伺服器控制項的事件模型的詳細資訊,請參閱ASP.NET Web Form 伺服器控制項事件模型For more information on the server control event model, see ASP.NET Web Forms Server Control Event Model.

當時或之前的頁面註冊控制項Page_PreRender頁面生命週期的事件。Register controls with the page at or before the Page_PreRender event of the page life cycle.