ClientScriptManager.GetCallbackEventReference Método

Definição

Obtém uma referência a uma função de cliente que, quando invocada, inicia um retorno de chamada do cliente para um evento de servidor.

Sobrecargas

GetCallbackEventReference(Control, String, String, String)

Obtém uma referência a uma função de cliente que, quando invocada, inicia um retorno de chamada do cliente para um evento de servidor. A função do cliente para esse método sobrecarregado inclui um controle, argumento, script de cliente e contexto especificados.

GetCallbackEventReference(Control, String, String, String, Boolean)

Obtém uma referência a uma função de cliente que, quando invocada, inicia um retorno de chamada do cliente para eventos de servidor. A função do cliente para esse método sobrecarregado inclui um controle, um argumento, um script de cliente, um contexto e um valor booliano especificados.

GetCallbackEventReference(String, String, String, String, String, Boolean)

Obtém uma referência a uma função de cliente que, quando invocada, inicia um retorno de chamada do cliente para eventos de servidor. A função do cliente para esse método sobrecarregado inclui um destino, argumento, script de cliente, contexto, manipulador de erro e valor booliano especificados.

GetCallbackEventReference(Control, String, String, String, String, Boolean)

Obtém uma referência a uma função de cliente que, quando invocada, inicia um retorno de chamada do cliente para eventos de servidor. A função do cliente para esse método sobrecarregado inclui um controle, um argumento, um script de cliente, um contexto, um manipulador de erros e m valor booliano especificados.

GetCallbackEventReference(Control, String, String, String)

Obtém uma referência a uma função de cliente que, quando invocada, inicia um retorno de chamada do cliente para um evento de servidor. A função do cliente para esse método sobrecarregado inclui um controle, argumento, script de cliente e contexto especificados.

public:
 System::String ^ GetCallbackEventReference(System::Web::UI::Control ^ control, System::String ^ argument, System::String ^ clientCallback, System::String ^ context);
public string GetCallbackEventReference (System.Web.UI.Control control, string argument, string clientCallback, string context);
member this.GetCallbackEventReference : System.Web.UI.Control * string * string * string -> string
Public Function GetCallbackEventReference (control As Control, argument As String, clientCallback As String, context As String) As String

Parâmetros

control
Control

O Control do servidor que manipula o retorno de chamada do cliente. O controle deve implementar a interface ICallbackEventHandler e fornecer um método RaiseCallbackEvent(String).

argument
String

Um argumento passado do script de cliente para o servidor Método RaiseCallbackEvent(String).

clientCallback
String

O nome do manipulador de eventos do cliente que recebe o resultado do evento do servidor com êxito.

context
String

O script de cliente avaliado no cliente antes de iniciar o retorno de chamada. O resultado do script é passado de volta para o manipulador de eventos do cliente.

Retornos

String

O nome de uma função de cliente que invoca o retorno de chamada do cliente.

Exceções

O Control especificado é null.

O Control especificado não implementa a interface ICallbackEventHandler.

Exemplos

O exemplo de código a seguir demonstra como usar duas sobrecargas do GetCallbackEventReference método em um cenário de retorno de chamada do cliente que incrementa inteiros.

Dois mecanismos de retorno de chamada são mostrados; a diferença entre eles é o uso do context parâmetro. Uma ReceiveServerData1 função de retorno de chamada do cliente é fornecida usando o context parâmetro. Por outro lado, a ReceiveServerData2 função de retorno de chamada do cliente é definida em um <script> bloco na página. Um RaiseCallbackEvent método é o manipulador de servidor que incrementa o valor passado para ele e o GetCallbackResult método retorna o valor incrementado como uma cadeia de caracteres. Se o RaiseCallbackEvent método retornar um erro, a ProcessCallBackError função cliente será chamada.

<%@ Page Language="C#" %>
<%@ Implements Interface="System.Web.UI.ICallbackEventHandler" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    
    public int cbCount = 0;
    
    // Define method that processes the callbacks on server.
    public void RaiseCallbackEvent(String eventArgument)
    {
        cbCount = Convert.ToInt32(eventArgument) + 1;
    }

    // Define method that returns callback result.
    public string GetCallbackResult()
    {
        return cbCount.ToString();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        // Define a StringBuilder to hold messages to output.
        StringBuilder sb = new StringBuilder();

        // Check if this is a postback.
        sb.Append("No page postbacks have occurred.");
        if (Page.IsPostBack)
        {
            sb.Append("A page postback has occurred.");
        }

        // Write out any messages.
        MyLabel.Text = sb.ToString();

        // Get a ClientScriptManager reference from the Page class.
        ClientScriptManager cs = Page.ClientScript;

        // Define one of the callback script's context.
        // The callback script will be defined in a script block on the page.
        StringBuilder context1 = new StringBuilder();
        context1.Append("function ReceiveServerData1(arg, context)");
        context1.Append("{");
        context1.Append("Message1.innerText =  arg;");
        context1.Append("value1 = arg;");
        context1.Append("}");

        // Define callback references.
        String cbReference1 = cs.GetCallbackEventReference(this, "arg", 
            "ReceiveServerData1", context1.ToString());
        String cbReference2 = cs.GetCallbackEventReference("'" + 
            Page.UniqueID + "'", "arg", "ReceiveServerData2", "", 
            "ProcessCallBackError", false);
        String callbackScript1 = "function CallTheServer1(arg, context) {" + 
            cbReference1 + "; }";
        String callbackScript2 = "function CallTheServer2(arg, context) {" + 
            cbReference2 + "; }";

        // Register script blocks will perform call to the server.
        cs.RegisterClientScriptBlock(this.GetType(), "CallTheServer1", 
            callbackScript1, true);
        cs.RegisterClientScriptBlock(this.GetType(), "CallTheServer2", 
            callbackScript2, true);

    }
</script>

<script type="text/javascript">
var value1 = 0;
var value2 = 0;
function ReceiveServerData2(arg, context)
{
    Message2.innerText = arg;
    value2 = arg;
}
function ProcessCallBackError(arg, context)
{
    Message2.innerText = 'An error has occurred.';
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>ClientScriptManager Example</title>
</head>
<body>
    <form id="Form1" 
          runat="server">
    <div>
      Callback 1 result: <span id="Message1">0</span>
      <br />
      Callback 2 result: <span id="Message2">0</span>
      <br /> <br />
      <input type="button" 
             value="ClientCallBack1" 
             onclick="CallTheServer1(value1, alert('Increment value'))"/>    
      <input type="button" 
             value="ClientCallBack2" 
             onclick="CallTheServer2(value2, alert('Increment value'))"/>
      <br /> <br />
      <asp:Label id="MyLabel" 
                 runat="server"></asp:Label>
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ Implements Interface="System.Web.UI.ICallbackEventHandler" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
  
    Public cbCount As Integer = 0
    
    ' Define method that processes the callbacks on server.
    Public Sub RaiseCallbackEvent(ByVal eventArgument As String) _
    Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent
        
        cbCount = Convert.ToInt32(eventArgument) + 1
        
    End Sub

    ' Define method that returns callback result.
    Public Function GetCallbackResult() _
    As String Implements _
    System.Web.UI.ICallbackEventHandler.GetCallbackResult

        Return cbCount.ToString()
        
    End Function
    
    
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    
        ' Define a StringBuilder to hold messages to output.
        Dim sb As New StringBuilder()
    
        ' Check if this is a postback.
        sb.Append("No page postbacks have occurred.")
        If (Page.IsPostBack) Then
      
            sb.Append("A page postback has occurred.")
      
        End If
    
        ' Write out any messages.
        MyLabel.Text = sb.ToString()
    
        ' Get a ClientScriptManager reference from the Page class.
        Dim cs As ClientScriptManager = Page.ClientScript

        ' Define one of the callback script's context.
        ' The callback script will be defined in a script block on the page.
        Dim context1 As New StringBuilder()
        context1.Append("function ReceiveServerData1(arg, context)")
        context1.Append("{")
        context1.Append("Message1.innerText =  arg;")
        context1.Append("value1 = arg;")
        context1.Append("}")
    
        ' Define callback references.
        Dim cbReference1 As String = cs.GetCallbackEventReference(Me, "arg", _
            "ReceiveServerData1", context1.ToString())
        Dim cbReference2 As String = cs.GetCallbackEventReference("'" & _
            Page.UniqueID & "'", "arg", "ReceiveServerData2", "", "ProcessCallBackError", False)
        Dim callbackScript1 As String = "function CallTheServer1(arg, context) {" + _
            cbReference1 + "; }"
        Dim callbackScript2 As String = "function CallTheServer2(arg, context) {" + _
            cbReference2 + "; }"
    
        ' Register script blocks will perform call to the server.
        cs.RegisterClientScriptBlock(Me.GetType(), "CallTheServer1", _
            callbackScript1, True)
        cs.RegisterClientScriptBlock(Me.GetType(), "CallTheServer2", _
            callbackScript2, True)
    
    End Sub
</script>

<script type="text/javascript">
var value1 = 0;
var value2 = 0;
function ReceiveServerData2(arg, context)
{
    Message2.innerText = arg;
    value2 = arg;
}
function ProcessCallBackError(arg, context)
{
    Message2.innerText = 'An error has occurred.';
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>ClientScriptManager Example</title>
</head>
<body>
    <form id="Form1" 
          runat="server">
    <div>
      Callback 1 result: <span id="Message1">0</span>
      <br />
      Callback 2 result: <span id="Message2">0</span>
      <br /> <br />
      <input type="button" 
             value="ClientCallBack1" 
             onclick="CallTheServer1(value1, alert('Increment value'))"/>    
      <input type="button" 
             value="ClientCallBack2" 
             onclick="CallTheServer2(value2, alert('Increment value'))"/>
      <br /> <br />
      <asp:Label id="MyLabel" 
                 runat="server"></asp:Label>
    </div>
    </form>
</body>
</html>

Comentários

O GetCallbackEventReference(Control, String, String, String) método executa um retorno de chamada fora de banda para o servidor que é uma versão modificada do ciclo de vida normal de uma página. Para obter mais informações, consulte Implementando retornos de chamada do cliente sem postbacks.

Observação

Quando o navegador é Microsoft Internet Explorer (versão 5.0 ou posterior), o mecanismo de retorno de chamada de script é implementado por meio do objeto COM Microsoft.XmlHttp e exige que o navegador seja definido para executar controles ActiveX. Para outros navegadores, um XMLHttpRequest usando o DOM (Modelo de Objeto de Documento) local do navegador é usado. Para verificar se um navegador dá suporte a retornos de chamada do cliente, use a SupportsCallback propriedade. Para verificar se um navegador dá suporte a XML por HTTP, use a SupportsXmlHttp propriedade. Ambas as propriedades são acessíveis por meio da Browser propriedade do objeto ASP.NET intrínseco Request .

A GetCallbackEventReference sobrecarga do GetCallbackEventReference método executa um retorno de chamada de forma síncrona usando XML por HTTP. Ao enviar dados de forma síncrona em um cenário de retorno de chamada, os retornos de chamada síncronos retornam imediatamente e não bloqueiam o navegador. Nenhum retorno de chamada de dois retornos de chamada síncronos pode ser executado ao mesmo tempo no navegador. Se um segundo retorno de chamada síncrono for acionado enquanto um estiver pendente no momento, o segundo retorno de chamada síncrono cancelará o primeiro e apenas o segundo retorno de chamada retornará.

Para enviar dados de forma assíncrona, use uma das sobrecargas que usa o useAsync parâmetro, que é um valor booliano que controla esse comportamento. No cenário assíncrono, você pode ter vários retornos de chamada pendentes; no entanto, a ordem na qual eles retornam não é garantida para corresponder à ordem em que foram iniciados.

Além disso, essa sobrecarga do GetCallbackEventReference método especifica nenhuma função de cliente para lidar com o caso de uma condição de erro gerada pelo RaiseCallbackEvent método. Para especificar um manipulador de retorno de chamada de erro do cliente, use uma das sobrecargas que usa o clientErrorCallback parâmetro.

O GetCallbackEventReference(Control, String, String, String) método usa um parâmetro de cadeia de caracteres argument opcional e retorna uma cadeia de caracteres. Para passar ou receber vários valores, concatene valores na cadeia de caracteres de entrada ou de retorno, respectivamente.

Observação

Evite usar o estado de exibição na implementação de propriedades de página ou controle que precisam ser atualizadas durante operações de retorno de chamada de script. Se as propriedades forem para sobreviver às solicitações de página, você poderá usar o estado da sessão.

Confira também

Aplica-se a

GetCallbackEventReference(Control, String, String, String, Boolean)

Obtém uma referência a uma função de cliente que, quando invocada, inicia um retorno de chamada do cliente para eventos de servidor. A função do cliente para esse método sobrecarregado inclui um controle, um argumento, um script de cliente, um contexto e um valor booliano especificados.

public:
 System::String ^ GetCallbackEventReference(System::Web::UI::Control ^ control, System::String ^ argument, System::String ^ clientCallback, System::String ^ context, bool useAsync);
public string GetCallbackEventReference (System.Web.UI.Control control, string argument, string clientCallback, string context, bool useAsync);
member this.GetCallbackEventReference : System.Web.UI.Control * string * string * string * bool -> string
Public Function GetCallbackEventReference (control As Control, argument As String, clientCallback As String, context As String, useAsync As Boolean) As String

Parâmetros

control
Control

O Control do servidor que manipula o retorno de chamada do cliente. O controle deve implementar a interface ICallbackEventHandler e fornecer um método RaiseCallbackEvent(String).

argument
String

Um argumento passado do script de cliente para o servidor Método RaiseCallbackEvent(String).

clientCallback
String

O nome do manipulador de eventos do cliente que recebe o resultado do evento do servidor com êxito.

context
String

O script de cliente avaliado no cliente antes de iniciar o retorno de chamada. O resultado do script é passado de volta para o manipulador de eventos do cliente.

useAsync
Boolean

true para executar o retorno de chamada de forma assíncrona; false para executar o retorno de chamada de forma síncrona.

Retornos

String

O nome de uma função de cliente que invoca o retorno de chamada do cliente.

Exceções

O Control especificado é null.

O Control especificado não implementa a interface ICallbackEventHandler.

Comentários

Essa sobrecarga do GetCallbackEventReference método requer um useAsync parâmetro, que permite que você execute o retorno de chamada do cliente de forma assíncrona definindo o valor como true. As versões de sobrecarga desse método que não exigem o useAsync parâmetro definem o valor como false por padrão.

Para obter mais informações sobre esse método, consulte as observações do método de sobrecarga GetCallbackEventReference .

Confira também

Aplica-se a

GetCallbackEventReference(String, String, String, String, String, Boolean)

Obtém uma referência a uma função de cliente que, quando invocada, inicia um retorno de chamada do cliente para eventos de servidor. A função do cliente para esse método sobrecarregado inclui um destino, argumento, script de cliente, contexto, manipulador de erro e valor booliano especificados.

public:
 System::String ^ GetCallbackEventReference(System::String ^ target, System::String ^ argument, System::String ^ clientCallback, System::String ^ context, System::String ^ clientErrorCallback, bool useAsync);
public string GetCallbackEventReference (string target, string argument, string clientCallback, string context, string clientErrorCallback, bool useAsync);
member this.GetCallbackEventReference : string * string * string * string * string * bool -> string
Public Function GetCallbackEventReference (target As String, argument As String, clientCallback As String, context As String, clientErrorCallback As String, useAsync As Boolean) As String

Parâmetros

target
String

O nome de um servidor Control que manipula o retorno de chamada do cliente. O controle deve implementar a interface ICallbackEventHandler e fornecer um método RaiseCallbackEvent(String).

argument
String

Um argumento passado do script de cliente para o servidor Método RaiseCallbackEvent(String).

clientCallback
String

O nome do manipulador de eventos do cliente que recebe o resultado do evento do servidor com êxito.

context
String

O script de cliente avaliado no cliente antes de iniciar o retorno de chamada. O resultado do script é passado de volta para o manipulador de eventos do cliente.

clientErrorCallback
String

O nome do manipulador de eventos do cliente que recebe o resultado quando ocorre um erro no manipulador de eventos do servidor.

useAsync
Boolean

true para executar o retorno de chamada de forma assíncrona; false para executar o retorno de chamada de forma síncrona.

Retornos

String

O nome de uma função de cliente que invoca o retorno de chamada do cliente.

Exemplos

O exemplo de código a seguir demonstra como usar duas sobrecargas do GetCallbackEventReference método em um cenário de retorno de chamada do cliente que incrementa inteiros.

Dois mecanismos de retorno de chamada são mostrados; a diferença entre eles é o uso do context parâmetro. Uma ReceiveServerData1 função de retorno de chamada do cliente é fornecida usando o context parâmetro. Por outro lado, a função de retorno de chamada do ReceiveServerData2 cliente é definida em um <script> bloco na página. Um RaiseCallbackEvent método é o manipulador de servidor que incrementa o valor passado para ele e o GetCallbackResult método retorna o valor incrementado como uma cadeia de caracteres. Se o RaiseCallbackEvent método retornar um erro, a função ProcessCallBackError cliente será chamada.

<%@ Page Language="C#" %>
<%@ Implements Interface="System.Web.UI.ICallbackEventHandler" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    
    public int cbCount = 0;
    
    // Define method that processes the callbacks on server.
    public void RaiseCallbackEvent(String eventArgument)
    {
        cbCount = Convert.ToInt32(eventArgument) + 1;
    }

    // Define method that returns callback result.
    public string GetCallbackResult()
    {
        return cbCount.ToString();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        // Define a StringBuilder to hold messages to output.
        StringBuilder sb = new StringBuilder();

        // Check if this is a postback.
        sb.Append("No page postbacks have occurred.");
        if (Page.IsPostBack)
        {
            sb.Append("A page postback has occurred.");
        }

        // Write out any messages.
        MyLabel.Text = sb.ToString();

        // Get a ClientScriptManager reference from the Page class.
        ClientScriptManager cs = Page.ClientScript;

        // Define one of the callback script's context.
        // The callback script will be defined in a script block on the page.
        StringBuilder context1 = new StringBuilder();
        context1.Append("function ReceiveServerData1(arg, context)");
        context1.Append("{");
        context1.Append("Message1.innerText =  arg;");
        context1.Append("value1 = arg;");
        context1.Append("}");

        // Define callback references.
        String cbReference1 = cs.GetCallbackEventReference(this, "arg", 
            "ReceiveServerData1", context1.ToString());
        String cbReference2 = cs.GetCallbackEventReference("'" + 
            Page.UniqueID + "'", "arg", "ReceiveServerData2", "", 
            "ProcessCallBackError", false);
        String callbackScript1 = "function CallTheServer1(arg, context) {" + 
            cbReference1 + "; }";
        String callbackScript2 = "function CallTheServer2(arg, context) {" + 
            cbReference2 + "; }";

        // Register script blocks will perform call to the server.
        cs.RegisterClientScriptBlock(this.GetType(), "CallTheServer1", 
            callbackScript1, true);
        cs.RegisterClientScriptBlock(this.GetType(), "CallTheServer2", 
            callbackScript2, true);

    }
</script>

<script type="text/javascript">
var value1 = 0;
var value2 = 0;
function ReceiveServerData2(arg, context)
{
    Message2.innerText = arg;
    value2 = arg;
}
function ProcessCallBackError(arg, context)
{
    Message2.innerText = 'An error has occurred.';
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>ClientScriptManager Example</title>
</head>
<body>
    <form id="Form1" 
          runat="server">
    <div>
      Callback 1 result: <span id="Message1">0</span>
      <br />
      Callback 2 result: <span id="Message2">0</span>
      <br /> <br />
      <input type="button" 
             value="ClientCallBack1" 
             onclick="CallTheServer1(value1, alert('Increment value'))"/>    
      <input type="button" 
             value="ClientCallBack2" 
             onclick="CallTheServer2(value2, alert('Increment value'))"/>
      <br /> <br />
      <asp:Label id="MyLabel" 
                 runat="server"></asp:Label>
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ Implements Interface="System.Web.UI.ICallbackEventHandler" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
  
    Public cbCount As Integer = 0
    
    ' Define method that processes the callbacks on server.
    Public Sub RaiseCallbackEvent(ByVal eventArgument As String) _
    Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent
        
        cbCount = Convert.ToInt32(eventArgument) + 1
        
    End Sub

    ' Define method that returns callback result.
    Public Function GetCallbackResult() _
    As String Implements _
    System.Web.UI.ICallbackEventHandler.GetCallbackResult

        Return cbCount.ToString()
        
    End Function
    
    
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    
        ' Define a StringBuilder to hold messages to output.
        Dim sb As New StringBuilder()
    
        ' Check if this is a postback.
        sb.Append("No page postbacks have occurred.")
        If (Page.IsPostBack) Then
      
            sb.Append("A page postback has occurred.")
      
        End If
    
        ' Write out any messages.
        MyLabel.Text = sb.ToString()
    
        ' Get a ClientScriptManager reference from the Page class.
        Dim cs As ClientScriptManager = Page.ClientScript

        ' Define one of the callback script's context.
        ' The callback script will be defined in a script block on the page.
        Dim context1 As New StringBuilder()
        context1.Append("function ReceiveServerData1(arg, context)")
        context1.Append("{")
        context1.Append("Message1.innerText =  arg;")
        context1.Append("value1 = arg;")
        context1.Append("}")
    
        ' Define callback references.
        Dim cbReference1 As String = cs.GetCallbackEventReference(Me, "arg", _
            "ReceiveServerData1", context1.ToString())
        Dim cbReference2 As String = cs.GetCallbackEventReference("'" & _
            Page.UniqueID & "'", "arg", "ReceiveServerData2", "", "ProcessCallBackError", False)
        Dim callbackScript1 As String = "function CallTheServer1(arg, context) {" + _
            cbReference1 + "; }"
        Dim callbackScript2 As String = "function CallTheServer2(arg, context) {" + _
            cbReference2 + "; }"
    
        ' Register script blocks will perform call to the server.
        cs.RegisterClientScriptBlock(Me.GetType(), "CallTheServer1", _
            callbackScript1, True)
        cs.RegisterClientScriptBlock(Me.GetType(), "CallTheServer2", _
            callbackScript2, True)
    
    End Sub
</script>

<script type="text/javascript">
var value1 = 0;
var value2 = 0;
function ReceiveServerData2(arg, context)
{
    Message2.innerText = arg;
    value2 = arg;
}
function ProcessCallBackError(arg, context)
{
    Message2.innerText = 'An error has occurred.';
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>ClientScriptManager Example</title>
</head>
<body>
    <form id="Form1" 
          runat="server">
    <div>
      Callback 1 result: <span id="Message1">0</span>
      <br />
      Callback 2 result: <span id="Message2">0</span>
      <br /> <br />
      <input type="button" 
             value="ClientCallBack1" 
             onclick="CallTheServer1(value1, alert('Increment value'))"/>    
      <input type="button" 
             value="ClientCallBack2" 
             onclick="CallTheServer2(value2, alert('Increment value'))"/>
      <br /> <br />
      <asp:Label id="MyLabel" 
                 runat="server"></asp:Label>
    </div>
    </form>
</body>
</html>

Comentários

Essa sobrecarga do GetCallbackEventReference método usa um target parâmetro de cadeia de caracteres em vez de um Control parâmetro. Use essa sobrecarga quando quiser que o retorno de chamada volte para algo diferente de uma cadeia de caracteres que contém o UniqueID controle.

Além disso, essa sobrecarga do GetCallbackEventReference método requer um useAsync e um clientErrorCallback parâmetro. O useAsync parâmetro permite que você execute o retorno de chamada do cliente de forma assíncrona definindo o valor como true. As versões de sobrecarga desse método que não exigem o useAsync parâmetro definem o valor como false por padrão. O clientErrorCallback parâmetro permite que você defina o nome da função cliente que é chamada se o manipulador de servidor, o RaiseCallbackEvent método, retornar um erro. As versões de sobrecarga desse método que não exigem o clientErrorCallback parâmetro definem o valor como nulo.

Para obter mais informações sobre esse método, consulte as observações para o método de sobrecarga GetCallbackEventReference .

Confira também

Aplica-se a

GetCallbackEventReference(Control, String, String, String, String, Boolean)

Obtém uma referência a uma função de cliente que, quando invocada, inicia um retorno de chamada do cliente para eventos de servidor. A função do cliente para esse método sobrecarregado inclui um controle, um argumento, um script de cliente, um contexto, um manipulador de erros e m valor booliano especificados.

public:
 System::String ^ GetCallbackEventReference(System::Web::UI::Control ^ control, System::String ^ argument, System::String ^ clientCallback, System::String ^ context, System::String ^ clientErrorCallback, bool useAsync);
public string GetCallbackEventReference (System.Web.UI.Control control, string argument, string clientCallback, string context, string clientErrorCallback, bool useAsync);
member this.GetCallbackEventReference : System.Web.UI.Control * string * string * string * string * bool -> string
Public Function GetCallbackEventReference (control As Control, argument As String, clientCallback As String, context As String, clientErrorCallback As String, useAsync As Boolean) As String

Parâmetros

control
Control

O Control do servidor que manipula o retorno de chamada do cliente. O controle deve implementar a interface ICallbackEventHandler e fornecer um método RaiseCallbackEvent(String).

argument
String

Um argumento passado do script de cliente para o método RaiseCallbackEvent(String) do servidor.

clientCallback
String

O nome do manipulador de eventos do cliente que recebe o resultado do evento do servidor com êxito.

context
String

O script de cliente avaliado no cliente antes de iniciar o retorno de chamada. O resultado do script é passado de volta para o manipulador de eventos do cliente.

clientErrorCallback
String

O nome do manipulador de eventos do cliente que recebe o resultado quando ocorre um erro no manipulador de eventos do servidor.

useAsync
Boolean

true para executar o retorno de chamada de forma assíncrona; false para executar o retorno de chamada de forma síncrona.

Retornos

String

O nome de uma função de cliente que invoca o retorno de chamada do cliente.

Exceções

O Control especificado é null.

O Control especificado não implementa a interface ICallbackEventHandler.

Comentários

Essa sobrecarga do GetCallbackEventReference método requer um e um useAsync clientErrorCallback parâmetro. O useAsync parâmetro permite que você execute o retorno de chamada do cliente de forma assíncrona definindo o valor como true. As versões de sobrecarga desse método que não exigem o useAsync parâmetro definem o valor false como por padrão. O clientErrorCallback parâmetro permite que você defina o nome da função cliente que é chamada se o manipulador de servidor (o RaiseCallbackEvent método) retornar um erro. As versões de sobrecarga desse método que não exigem o clientErrorCallback parâmetro definem o valor como nulo.

Para obter mais informações sobre esse método, consulte as observações para o método de sobrecarga GetCallbackEventReference .

Confira também

Aplica-se a