Page.RegisterRequiresPostBack(Control) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Registers a control as one that requires postback handling when the page is posted back to the server.
public:
void RegisterRequiresPostBack(System::Web::UI::Control ^ control);
public void RegisterRequiresPostBack (System.Web.UI.Control control);
member this.RegisterRequiresPostBack : System.Web.UI.Control -> unit
Public Sub RegisterRequiresPostBack (control As Control)
Parameters
- control
- Control
The control to be registered.
Exceptions
The control to register does not implement the IPostBackDataHandler interface.
Examples
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 controls implement the IPostBackDataHandler interface.
Important
This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. 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)
{
this.RegisterRequiresPostBack(myTextBox);
}
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)
Me.RegisterRequiresPostBack(myTextBox)
End Sub
Remarks
The control to be registered must implement the IPostBackDataHandler interface or an HttpException is raised. When implemented by a control, the IPostBackDataHandler interface enables handling of post back data and raising of any post back data changed events. For more information on the server control event model, see ASP.NET Web Forms Server Control Event Model.
Register controls with the page at or before the Page_PreRender
event of the page life cycle.
Applies to
See also
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기