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 de forma predeterminada del servidor Web local en un TextBox 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 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 un controlador se ejecuta en un momento.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 una sola 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.

Se llama a los controladores asincrónicos entre el PreRender y PreRenderComplete eventos.The asynchronous handlers are called between the PreRender and PreRenderComplete events.

Primero, todos los Page eventos (a través de la PreRender eventos) se registran ejecución y, a continuación, cada BeginEventHandler se llama al método.First, all Page events (through the PreRender event) are run, and then each registered BeginEventHandler method is called. Cuando finalice el controlador, el correspondiente EndEventHandler se llama al método.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.

Una vez que se ha llamado a los controladores de eventos asincrónicos registrados, el resto de los eventos de página se denominan, empezando por el PreRenderComplete eventos.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 de forma predeterminada del servidor Web local en un TextBox 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 que requieren información de estado para 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 requiere la aplicación para transferir información entre los delegados de controlador de eventos especificados en el beginHandler y endHandler parámetros.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 un controlador se ejecuta en un momento.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 una sola 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.

Se llama a los controladores asincrónicos entre el PreRender y PreRenderComplete eventos.The asynchronous handlers are called between the PreRender and PreRenderComplete events.

Primero, todos los Page eventos (a través de la PreRender eventos) se registran ejecución y, a continuación, cada BeginEventHandler se llama al método.First, all Page events (through the PreRender event) are run, and then each registered BeginEventHandler method is called. Cuando finalice el controlador, el correspondiente EndEventHandler se llama al método.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.

Una vez que se ha llamado a los controladores de eventos asincrónicos registrados, el resto de los eventos de página se denominan, empezando por el PreRenderComplete eventos.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