Page.AddOnPreRenderCompleteAsync Page.AddOnPreRenderCompleteAsync Page.AddOnPreRenderCompleteAsync Page.AddOnPreRenderCompleteAsync Method

Definición

Registra los delegados de controlador de eventos inicial y final de una página asincrónica.Registers beginning and ending event handler delegates for an asynchronous page.

Sobrecargas

AddOnPreRenderCompleteAsync(BeginEventHandler, EndEventHandler) AddOnPreRenderCompleteAsync(BeginEventHandler, EndEventHandler) AddOnPreRenderCompleteAsync(BeginEventHandler, EndEventHandler) AddOnPreRenderCompleteAsync(BeginEventHandler, EndEventHandler)

Registra los delegados de controlador de eventos inicial y final que no requieren información de estado para una página asincrónica.Registers beginning and ending event handler delegates that do not require state information for an asynchronous page.

AddOnPreRenderCompleteAsync(BeginEventHandler, EndEventHandler, Object) AddOnPreRenderCompleteAsync(BeginEventHandler, EndEventHandler, Object) AddOnPreRenderCompleteAsync(BeginEventHandler, EndEventHandler, Object) AddOnPreRenderCompleteAsync(BeginEventHandler, EndEventHandler, Object)

Registra los delegados de controlador de eventos inicial y final de una página asincrónica.Registers beginning and ending event handler delegates for an asynchronous page.

AddOnPreRenderCompleteAsync(BeginEventHandler, EndEventHandler) AddOnPreRenderCompleteAsync(BeginEventHandler, EndEventHandler) AddOnPreRenderCompleteAsync(BeginEventHandler, EndEventHandler) AddOnPreRenderCompleteAsync(BeginEventHandler, EndEventHandler)

Registra los delegados de controlador de eventos inicial y final que no requieren información de estado para una página asincrónica.Registers beginning and ending event handler delegates that do not require state information for an asynchronous page.

public:
 void AddOnPreRenderCompleteAsync(System::Web::BeginEventHandler ^ beginHandler, System::Web::EndEventHandler ^ endHandler);
public void AddOnPreRenderCompleteAsync (System.Web.BeginEventHandler beginHandler, System.Web.EndEventHandler endHandler);
member this.AddOnPreRenderCompleteAsync : System.Web.BeginEventHandler * System.Web.EndEventHandler -> unit
Public Sub AddOnPreRenderCompleteAsync (beginHandler As BeginEventHandler, endHandler As EndEventHandler)

Parámetros

beginHandler
BeginEventHandler BeginEventHandler BeginEventHandler BeginEventHandler

Delegado del método BeginEventHandler.The delegate for the BeginEventHandler method.

endHandler
EndEventHandler EndEventHandler EndEventHandler EndEventHandler

Delegado del método EndEventHandler.The delegate for the EndEventHandler method.

Excepciones

La directiva de página <async> no está establecida en true.The <async> page directive is not set to true.

O bien-or- Se ha llamado al método AddOnPreRenderCompleteAsync(BeginEventHandler, EndEventHandler) después del evento PreRender.The AddOnPreRenderCompleteAsync(BeginEventHandler, EndEventHandler) method is called after the PreRender event.

Ejemplos

En el ejemplo de código siguiente se usa una solicitud asincrónica para mostrar el código fuente HTML de la página predeterminada del servidor Web local TextBox en un control.The following code example uses an asynchronous request to display the HTML source code of the local Web server's default page in a TextBox control.

Importante

Este ejemplo tiene un cuadro de texto que acepta datos proporcionados por el usuario, lo que puede suponer una amenaza para la seguridad.This example has a text box that accepts user input, which is a potential security threat. De forma predeterminada, ASP.NET Web Pages valida que los datos proporcionados por el usuario no incluyen elementos HTML ni de script.By default, ASP.NET Web pages validate that user input does not include script or HTML elements. Para más información, consulte Información general sobre los ataques mediante scripts.For more information, see Script Exploits Overview.

<%@ page language="C#" Async="true"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  System.Net.WebRequest myRequest;

  void Page_Load(object sender, EventArgs e)
  {
    Label1.Text = "Page_Load: thread #" + System.Threading.Thread.CurrentThread.GetHashCode();

    BeginEventHandler bh = new BeginEventHandler(this.BeginGetAsyncData);
    EndEventHandler eh = new EndEventHandler(this.EndGetAsyncData);

    AddOnPreRenderCompleteAsync(bh, eh);

    // Initialize the WebRequest.
    string address = "http://localhost/";

    myRequest = System.Net.WebRequest.Create(address);
  }

  IAsyncResult BeginGetAsyncData(Object src, EventArgs args, AsyncCallback cb, Object state)
  {
    Label2.Text = "BeginGetAsyncData: thread #" + System.Threading.Thread.CurrentThread.GetHashCode();
    return myRequest.BeginGetResponse(cb, state);
  }

  void EndGetAsyncData(IAsyncResult ar)
  {
    Label3.Text = "EndGetAsyncData: thread #" + System.Threading.Thread.CurrentThread.GetHashCode();

    System.Net.WebResponse myResponse = myRequest.EndGetResponse(ar);

    result.Text = new System.IO.StreamReader(myResponse.GetResponseStream()).ReadToEnd();
    myResponse.Close();
  }

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>
      Page.AddOnPreRenderCompleteAsync Example</title>
  </head>
  <body>
    <form id="form1" runat="server">
      <asp:label id="Label1" runat="server">
        Label 1</asp:label><br />
      <asp:label id="Label2" runat="server">
        Label 2</asp:label><br />
      <asp:label id="Label3" runat="server">
        Label 3</asp:label><br />
      <asp:textbox id="result" runat="server" textMode="multiLine" ReadOnly="true" columns="80" rows="25" />
    </form>
  </body>
</html>
<%@ page language="VB" Async="true"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  Dim myRequest As System.Net.WebRequest
  
  Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    Label1.Text = "Page_Load: Thread #" & System.Threading.Thread.CurrentThread.GetHashCode()
    
    Dim bh As New BeginEventHandler(AddressOf Me.BeginGetAsyncData)
    Dim eh As New EndEventHandler(AddressOf Me.EndGetAsyncData)
    
    Me.AddOnPreRenderCompleteAsync(bh, eh)
    
    ' Initialize the WebRequest object.
    Dim address As String
    address = "http://localhost/"
    myRequest = System.Net.WebRequest.Create(address)
    
  End Sub
  
  Function BeginGetAsyncData(ByVal src As Object, ByVal args As EventArgs, ByVal cb As AsyncCallback, ByVal state As Object) As IAsyncResult
    Label2.Text = "BeginGetAsyncData: Thread #" & System.Threading.Thread.CurrentThread.GetHashCode()
    Return Me.myRequest.BeginGetResponse(cb, state)
  End Function
  
  Sub EndGetAsyncData(ByVal ar As IAsyncResult)
    Label3.Text = "EndGetAsyncData: Thread #" & System.Threading.Thread.CurrentThread.GetHashCode()
    
    Dim myResponse As System.Net.WebResponse
    myResponse = Me.myRequest.EndGetResponse(ar)
    
    Dim reader As New System.IO.StreamReader(myResponse.GetResponseStream())
    result.Text = reader.ReadToEnd()
    myResponse.Close()
  End Sub
  
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>
      Page.AddOnPreRenderCompleteAsync Example</title>
  </head>
  <body>
    <form id="form1" runat="server">
      <asp:label id="Label1" runat="server">
        Label 1</asp:label><br />
      <asp:label id="Label2" runat="server">
        Label 2</asp:label><br />
      <asp:label id="Label3" runat="server">
        Label 3</asp:label><br />
      <asp:textbox id="result" runat="server" textMode="multiLine" ReadOnly="true" columns="80" rows="25" />
    </form>
  </body>
</html>

Comentarios

Use el AddOnPreRenderCompleteAsync método para agregar controladores a una página web asincrónica.Use the AddOnPreRenderCompleteAsync method to add handlers to an asynchronous Web page.

Puede registrar varios controladores asincrónicos; sin embargo, solo se ejecuta un controlador cada vez.You can register multiple asynchronous handlers; however, only one handler runs at a time. Si desea procesar varios métodos asincrónicos simultáneamente, debe usar un único BeginEventHandler método e iniciar varias operaciones asincrónicas desde ese controlador.If you want to process multiple asynchronous methods simultaneously, you should use a single BeginEventHandler method and launch multiple asynchronous operations from that handler.

Los controladores asincrónicos se llaman entre los PreRender eventos y. PreRenderCompleteThe asynchronous handlers are called between the PreRender and PreRenderComplete events.

En primer lugar Page , se ejecutan PreRender todos los eventos (a través del evento) BeginEventHandler y, a continuación, se llama a cada método registrado.First, all Page events (through the PreRender event) are run, and then each registered BeginEventHandler method is called. Cuando el controlador se completa, se llama EndEventHandler al método correspondiente.When the handler completes, the corresponding EndEventHandler method is called. Si hay varios controladores asincrónicos, se llama al controlador siguiente.If there are multiple asynchronous handlers, the next handler is called.

Después de llamar a los controladores de eventos asincrónicos registrados, se llama al resto de los eventos de página, comenzando por PreRenderComplete el evento.After the registered asynchronous event handlers have been called, the rest of the page events are called, beginning with the PreRenderComplete event.

Consulte también:

AddOnPreRenderCompleteAsync(BeginEventHandler, EndEventHandler, Object) AddOnPreRenderCompleteAsync(BeginEventHandler, EndEventHandler, Object) AddOnPreRenderCompleteAsync(BeginEventHandler, EndEventHandler, Object) AddOnPreRenderCompleteAsync(BeginEventHandler, EndEventHandler, Object)

Registra los delegados de controlador de eventos inicial y final de una página asincrónica.Registers beginning and ending event handler delegates for an asynchronous page.

public:
 void AddOnPreRenderCompleteAsync(System::Web::BeginEventHandler ^ beginHandler, System::Web::EndEventHandler ^ endHandler, System::Object ^ state);
public void AddOnPreRenderCompleteAsync (System.Web.BeginEventHandler beginHandler, System.Web.EndEventHandler endHandler, object state);
member this.AddOnPreRenderCompleteAsync : System.Web.BeginEventHandler * System.Web.EndEventHandler * obj -> unit
Public Sub AddOnPreRenderCompleteAsync (beginHandler As BeginEventHandler, endHandler As EndEventHandler, state As Object)

Parámetros

beginHandler
BeginEventHandler BeginEventHandler BeginEventHandler BeginEventHandler

Delegado del método BeginEventHandler.The delegate for the BeginEventHandler method.

endHandler
EndEventHandler EndEventHandler EndEventHandler EndEventHandler

Delegado del método EndEventHandler.The delegate for the EndEventHandler method.

state
Object Object Object Object

Objeto que contiene información de estado para los controladores de eventos.An object containing state information for the event handlers.

Excepciones

La directiva de página <async> no está establecida en true.The <async> page directive is not set to true.

o bien-or- Se ha llamado al método AddOnPreRenderCompleteAsync(BeginEventHandler, EndEventHandler) después del evento PreRender.The AddOnPreRenderCompleteAsync(BeginEventHandler, EndEventHandler) method is called after the PreRender event.

Ejemplos

En el ejemplo de código siguiente se usa una solicitud asincrónica para mostrar el código fuente HTML de la página predeterminada del servidor Web local TextBox en un control.The following code example uses an asynchronous request to display the HTML source code of the local Web server's default page in a TextBox control.

Importante

Este ejemplo tiene un cuadro de texto que acepta datos proporcionados por el usuario, lo que puede suponer una amenaza para la seguridad.This example has a text box that accepts user input, which is a potential security threat. De forma predeterminada, ASP.NET Web Pages valida que los datos proporcionados por el usuario no incluyen elementos HTML ni de script.By default, ASP.NET Web pages validate that user input does not include script or HTML elements. Para más información, consulte Información general sobre los ataques mediante scripts.For more information, see Script Exploits Overview.

<%@ page language="C#" Async="true"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  System.Net.WebRequest myRequest;

  void Page_Load(object sender, EventArgs e)
  {
    Label1.Text = "Page_Load: thread #" + System.Threading.Thread.CurrentThread.GetHashCode();

    BeginEventHandler bh = new BeginEventHandler(this.BeginGetAsyncData);
    EndEventHandler eh = new EndEventHandler(this.EndGetAsyncData);

    AddOnPreRenderCompleteAsync(bh, eh);

    // Initialize the WebRequest.
    string address = "http://localhost/";

    myRequest = System.Net.WebRequest.Create(address);
  }

  IAsyncResult BeginGetAsyncData(Object src, EventArgs args, AsyncCallback cb, Object state)
  {
    Label2.Text = "BeginGetAsyncData: thread #" + System.Threading.Thread.CurrentThread.GetHashCode();
    return myRequest.BeginGetResponse(cb, state);
  }

  void EndGetAsyncData(IAsyncResult ar)
  {
    Label3.Text = "EndGetAsyncData: thread #" + System.Threading.Thread.CurrentThread.GetHashCode();

    System.Net.WebResponse myResponse = myRequest.EndGetResponse(ar);

    result.Text = new System.IO.StreamReader(myResponse.GetResponseStream()).ReadToEnd();
    myResponse.Close();
  }

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>
      Page.AddOnPreRenderCompleteAsync Example</title>
  </head>
  <body>
    <form id="form1" runat="server">
      <asp:label id="Label1" runat="server">
        Label 1</asp:label><br />
      <asp:label id="Label2" runat="server">
        Label 2</asp:label><br />
      <asp:label id="Label3" runat="server">
        Label 3</asp:label><br />
      <asp:textbox id="result" runat="server" textMode="multiLine" ReadOnly="true" columns="80" rows="25" />
    </form>
  </body>
</html>
<%@ page language="VB" Async="true"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  Dim myRequest As System.Net.WebRequest
  
  Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    Label1.Text = "Page_Load: Thread #" & System.Threading.Thread.CurrentThread.GetHashCode()
    
    Dim bh As New BeginEventHandler(AddressOf Me.BeginGetAsyncData)
    Dim eh As New EndEventHandler(AddressOf Me.EndGetAsyncData)
    
    Me.AddOnPreRenderCompleteAsync(bh, eh)
    
    ' Initialize the WebRequest object.
    Dim address As String
    address = "http://localhost/"
    myRequest = System.Net.WebRequest.Create(address)
    
  End Sub
  
  Function BeginGetAsyncData(ByVal src As Object, ByVal args As EventArgs, ByVal cb As AsyncCallback, ByVal state As Object) As IAsyncResult
    Label2.Text = "BeginGetAsyncData: Thread #" & System.Threading.Thread.CurrentThread.GetHashCode()
    Return Me.myRequest.BeginGetResponse(cb, state)
  End Function
  
  Sub EndGetAsyncData(ByVal ar As IAsyncResult)
    Label3.Text = "EndGetAsyncData: Thread #" & System.Threading.Thread.CurrentThread.GetHashCode()
    
    Dim myResponse As System.Net.WebResponse
    myResponse = Me.myRequest.EndGetResponse(ar)
    
    Dim reader As New System.IO.StreamReader(myResponse.GetResponseStream())
    result.Text = reader.ReadToEnd()
    myResponse.Close()
  End Sub
  
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>
      Page.AddOnPreRenderCompleteAsync Example</title>
  </head>
  <body>
    <form id="form1" runat="server">
      <asp:label id="Label1" runat="server">
        Label 1</asp:label><br />
      <asp:label id="Label2" runat="server">
        Label 2</asp:label><br />
      <asp:label id="Label3" runat="server">
        Label 3</asp:label><br />
      <asp:textbox id="result" runat="server" textMode="multiLine" ReadOnly="true" columns="80" rows="25" />
    </form>
  </body>
</html>

Comentarios

Utilice el AddOnPreRenderCompleteAsync método para agregar controladores que requieran información de estado a una página web asincrónica.Use the AddOnPreRenderCompleteAsync method to add handlers that require state information to an asynchronous Web page. El objeto pasado en el state parámetro puede ser cualquier objeto que la aplicación requiera para transferir información entre los delegados de beginHandler controlador de endHandler eventos especificados en los parámetros y.The object passed in the state parameter can be any object that your application requires to transfer information between event handler delegates specified in the beginHandler and the endHandler parameters.

Puede registrar varios controladores asincrónicos; sin embargo, solo se ejecuta un controlador cada vez.You can register multiple asynchronous handlers; however, only one handler runs at a time. Si desea procesar varios métodos asincrónicos simultáneamente, debe usar un único BeginEventHandler método e iniciar varias operaciones asincrónicas desde ese controlador.If you want to process multiple asynchronous methods simultaneously, you should use a single BeginEventHandler method and launch multiple asynchronous operations from that handler.

Los controladores asincrónicos se llaman entre los PreRender eventos y. PreRenderCompleteThe asynchronous handlers are called between the PreRender and PreRenderComplete events.

En primer lugar Page , se ejecutan PreRender todos los eventos (a través del evento) BeginEventHandler y, a continuación, se llama a cada método registrado.First, all Page events (through the PreRender event) are run, and then each registered BeginEventHandler method is called. Cuando el controlador se completa, se llama EndEventHandler al método correspondiente.When the handler completes, the corresponding EndEventHandler method is called. Si hay varios controladores asincrónicos, se llama al controlador siguiente.If there are multiple asynchronous handlers, the next handler is called.

Después de llamar a los controladores de eventos asincrónicos registrados, se llama al resto de los eventos de página, comenzando por PreRenderComplete el evento.After the registered asynchronous event handlers have been called, the rest of the page events are called, beginning with the PreRenderComplete event.

Se aplica a