ScriptManager.RegisterAsyncPostBackControl(Control) Metoda
Definicja
Rejestruje formant jako wyzwalacz dla asynchronicznych ogłoszeń zwrotnych.Registers a control as a trigger for asynchronous postbacks.
public:
virtual void RegisterAsyncPostBackControl(System::Web::UI::Control ^ control);
public void RegisterAsyncPostBackControl (System.Web.UI.Control control);
abstract member RegisterAsyncPostBackControl : System.Web.UI.Control -> unit
override this.RegisterAsyncPostBackControl : System.Web.UI.Control -> unit
Public Sub RegisterAsyncPostBackControl (control As Control)
Parametry
- control
- Control
Kontrolka, która ma zostać zarejestrowana w celu asynchronicznego ogłaszania zwrotnego.The control to register for asynchronous postbacks.
Wyjątki
control
to null
.control
is null
.
Strona jest zarejestrowana jako asynchroniczny formant ogłaszania zwrotnego.The page is registered as an asynchronous postback control.
-lub--or-
Zarejestrowany formant nie implementuje INamingContainer IPostBackDataHandler interfejsów,, ani IPostBackEventHandler .The registered control does not implement the INamingContainer, IPostBackDataHandler, or IPostBackEventHandler interfaces.
Przykłady
Poniższy przykład pokazuje, jak wywołać RegisterAsyncPostBackControl metodę w celu zarejestrowania Button kontrolki, aby spowodowało ona aktualizację UpdatePanel zawartości kontrolki.The following example shows how to call the RegisterAsyncPostBackControl method to register a Button control so that it causes an update of an UpdatePanel control's content. ButtonFormant nie należy do UpdatePanel kontrolki.The Button control is not inside the UpdatePanel control. Pokazywane są dwa przyciski: Button1
i Button2
.Two buttons are shown: Button1
and Button2
. Button1
odświeża zawartość panelu, a następnie Button2
odświeża całą stronę.Button1
refreshes the content of the panel, and Button2
refreshes the whole page.
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager1.RegisterAsyncPostBackControl(Button1);
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "Panel refreshed at " + DateTime.Now.ToString();
}
protected void Button2_Click(object sender, EventArgs e)
{
Label1.Text = "Page refreshed.";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>ScriptManager RegisterAsyncPostBackControl Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"/>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<fieldset>
<legend>Update Panel</legend>
<asp:Label ID="Label1" runat="server">Initial postback occurred.</asp:Label>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="Button1" runat="server" Text="Update Panel" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="Refresh Page" OnClick="Button2_Click" />
</div>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C'DTD XHTML 1.0 Transitional'EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
ScriptManager1.RegisterAsyncPostBackControl(Button1)
End Sub
Protected Sub Button1_Click(ByVal Sender As Object, ByVal E As EventArgs)
Label1.Text = "Panel refreshed at " + DateTime.Now.ToString()
End Sub
Protected Sub Button2_Click(ByVal Sender As Object, ByVal E As EventArgs)
Label1.Text = "Page refreshed."
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>ScriptManager RegisterAsyncPostBackControl Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"/>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<fieldset>
<legend>Update Panel</legend>
<asp:Label ID="Label1" runat="server">Initial postback occurred.</asp:Label>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="Button1" runat="server" Text="Update Panel" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="Refresh Page" OnClick="Button2_Click" />
</div>
</form>
</body>
</html>
Poniższy przykład pokazuje, jak wywołać RegisterAsyncPostBackControl metodę w celu zarejestrowania kontrolki użytkownika, aby spowodować aktualizację UpdatePanel zawartości kontrolki.The following example shows how to call the RegisterAsyncPostBackControl method to register a user control so that it causes an update of an UpdatePanel control's content. Pierwszy przykład przedstawia stronę przy użyciu kontrolki użytkownika.The first example shows a page using the user control. Drugi przykład pokazuje kontrolkę użytkownika.The second example shows the user control.
<%@ Page Language="C#" %>
<%@ Register Src="Controls/WebUserControl.ascx" TagName="WebUserControl"
TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager1.RegisterAsyncPostBackControl(WebUserControl1);
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "Panel refreshed at " + DateTime.Now.ToString();
}
protected void WebUserControl1_Click(object sender, EventArgs e)
{
Label1.Text = "Panel refreshed at " + DateTime.Now.ToString() +
". Welcome " + WebUserControl1.Name + ". ";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>ScriptManager RegisterAsyncPostBackControl Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<fieldset>
<legend>Update Panel</legend>
<asp:Label ID="Label1" runat="server">Initial postback occurred.</asp:Label>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="Button1" runat="server" Text="Update Panel" OnClick="Button1_Click" />
<uc1:webusercontrol id="WebUserControl1" runat="server" oninnerclick="WebUserControl1_Click" />
</div>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ Register Src="Controls/WebUserControl.ascx" TagName="WebUserControl"
TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-'W3C'DTD XHTML 1.0 Transitional'EN"
"http:'www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
ScriptManager1.RegisterAsyncPostBackControl(WebUserControl1)
End Sub
Protected Sub Button1_Click(ByVal Sender As Object, ByVal E As EventArgs)
Label1.Text = "Panel refreshed at " + DateTime.Now.ToString()
End Sub
Protected Sub WebUserControl1_Click(ByVal Sender As Object, ByVal E As EventArgs)
Label1.Text = "Panel refreshed at " + DateTime.Now.ToString() + _
". Welcome " + WebUserControl1.Name + ". "
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>ScriptManager RegisterAsyncPostBackControl Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"/>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<fieldset>
<legend>Update Panel</legend>
<asp:Label ID="Label1" runat="server">Initial postback occurred.</asp:Label>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="Button1" runat="server" Text="Update Panel" OnClick="Button1_Click" />
<uc1:webusercontrol id="WebUserControl1" runat="server" oninnerclick="WebUserControl1_Click" />
</div>
</form>
</body>
</html>
Uwagi
RegisterAsyncPostBackControlMetoda umożliwia rejestrację formantów serwera sieci Web jako wyzwalaczy, tak aby wykonywały asynchroniczne ogłaszanie zwrotne zamiast synchronicznego ogłaszania zwrotnego.The RegisterAsyncPostBackControl method enables you to register Web server controls as triggers so that they perform an asynchronous postback instead of a synchronous postback. Gdy ChildrenAsTriggers Właściwość UpdatePanel kontrolki jest ustawiona na true
(co jest ustawieniem domyślnym), kontrolki ogłaszania zwrotnego wewnątrz UpdatePanel formantu są automatycznie rejestrowane jako asynchroniczne kontrolki ogłaszania zwrotnego.When the ChildrenAsTriggers property of an UpdatePanel control is set to true
(which is the default), postback controls inside the UpdatePanel control are automatically registered as asynchronous postback controls.
Użyj RegisterAsyncPostBackControl metody, aby zarejestrować kontrolki poza UpdatePanel kontrolką jako wyzwalacze dla asynchronicznego ogłaszania zwrotnego i potencjalnie zaktualizować zawartość panelu aktualizacji.Use the RegisterAsyncPostBackControl method to register controls outside an UpdatePanel control as triggers for asynchronous postbacks, and to potentially update the content of an update panel. Aby programowo zaktualizować UpdatePanel kontrolkę, wywołaj Update metodę.To update an UpdatePanel control programmatically, call the Update method.
Wyzwalacz można dodać deklaratywnie przy użyciu Triggers
elementu UpdatePanel formantu.You can add the trigger declaratively by using the Triggers
element of the UpdatePanel control. W programie Visual Studio Użyj okna dialogowego edytora kolekcji UpdatePanelTrigger projektanta.In Visual Studio, use the designer's UpdatePanelTrigger Collection Editor dialog box.