ClientScriptManager.GetCallbackEventReference 方法

定義

取得用戶端函式的參考,這個函式會在叫用時,啟始對伺服器事件的用戶端回呼。

多載

GetCallbackEventReference(Control, String, String, String)

取得用戶端函式的參考,這個函式會在叫用時,啟始對伺服器事件的用戶端回呼。 這個多載方法的用戶端函式包含指定的控制項、引數、用戶端指令碼和內容。

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

取得用戶端函式的參考,這個函式會在叫用時,啟始對伺服器事件的用戶端回呼。 這個多載方法的用戶端函式包含指定的控制項、引數、用戶端指令碼、內容和布林值。

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

取得用戶端函式的參考,這個函式會在叫用時,啟始對伺服器事件的用戶端回呼。 這個多載方法的用戶端函式包含指定的目標、引數、用戶端指令碼、內容、錯誤處理常式和布林值。

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

取得用戶端函式的參考,這個函式會在叫用時,啟始對伺服器事件的用戶端回呼。 這個多載方法的用戶端函式包含指定的控制項、引數、用戶端指令碼、內容、錯誤處理常式和布林值。

GetCallbackEventReference(Control, String, String, String)

取得用戶端函式的參考,這個函式會在叫用時,啟始對伺服器事件的用戶端回呼。 這個多載方法的用戶端函式包含指定的控制項、引數、用戶端指令碼和內容。

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

參數

control
Control

處理用戶端回呼的伺服器 Control。 控制項必須實作 ICallbackEventHandler 介面並提供 RaiseCallbackEvent(String) 方法。

argument
String

從用戶端指令碼傳遞到伺服器的引數

RaiseCallbackEvent(String) 方法。

clientCallback
String

會接收成功的伺服器事件結果的用戶端事件處理常式名稱。

context
String

在啟始回呼 (Callback) 之前,於用戶端上評估的用戶端指令碼。 指令碼的結果會傳回給用戶端事件處理常式。

傳回

叫用用戶端回呼的用戶端函式名稱。

例外狀況

指定的 Controlnull

範例

下列程式碼範例示範如何在遞增整數的用戶端回呼案例中使用 方法的 GetCallbackEventReference 兩個多載。

顯示兩個回呼機制;它們之間的差異是使用 context 參數。 ReceiveServerData1用戶端回呼函式是使用 context 參數來提供。 相反地, ReceiveServerData2 用戶端回呼函式是在頁面上的 <script> 區塊中定義。 方法是 RaiseCallbackEvent 伺服器處理常式,它會遞增傳遞給它的值,而 GetCallbackResult 方法會以字串的形式傳回遞增的值。 RaiseCallbackEvent如果方法傳回錯誤,則會 ProcessCallBackError 呼叫用戶端函式。

<%@ 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>

備註

方法 GetCallbackEventReference(Control, String, String, String) 會執行頻外回呼給屬於頁面一般生命週期已修改版本的伺服器。 如需詳細資訊,請參閱 實作不含回傳的用戶端回呼

注意

當瀏覽器Microsoft Internet Explorer (5.0 版或更新版本) 時,腳本回呼機制會透過Microsoft實作。XmlHttp COM 物件,而且需要將瀏覽器設定為執行 ActiveX 控制項。 對於其他瀏覽器,會使用瀏覽器的本機檔物件模型 XMLHttpRequest, (DOM) 。 若要檢查瀏覽器是否支援用戶端回呼,請使用 SupportsCallback 屬性。 若要檢查瀏覽器是否支援透過 HTTP 的 XML,請使用 SupportsXmlHttp 屬性。 這兩個屬性都可透過 Browser 內部 ASP.NET Request 物件的 屬性來存取。

方法 GetCallbackEventReference 的多 GetCallbackEventReference 載會使用透過 HTTP 的 XML 同步執行回呼。 在回呼案例中同步傳送資料時,同步回呼會立即傳回,而不會封鎖瀏覽器。 瀏覽器無法同時執行兩個同步回呼回呼。 如果第二個同步回呼在目前擱置時引發,第二個同步回呼會取消第一個,而且只會傳回第二個回呼。

若要以非同步方式傳送資料,請使用採用 參數的其中一個多載 useAsync ,這是控制此行為的布林值。 在非同步案例中,您可以有多個擱置的回呼;不過,它們傳回的順序不保證符合起始的順序。

此外,此方法的 GetCallbackEventReference 這個多載不會指定任何用戶端函式來處理 方法所產生的 RaiseCallbackEvent 錯誤狀況案例。 若要指定用戶端錯誤回呼處理常式,請使用採用 參數的其中一個多載 clientErrorCallback

方法 GetCallbackEventReference(Control, String, String, String) 會採用選擇性字串 argument 參數,並傳回字串。 若要傳入或接收多個值,請分別串連輸入或傳回字串中的值。

注意

避免在腳本回呼作業期間需要更新的頁面或控制項屬性實作中使用檢視狀態。 如果屬性要存留頁面要求,您可以使用會話狀態。

另請參閱

適用於

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

取得用戶端函式的參考,這個函式會在叫用時,啟始對伺服器事件的用戶端回呼。 這個多載方法的用戶端函式包含指定的控制項、引數、用戶端指令碼、內容和布林值。

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

參數

control
Control

處理用戶端回呼的伺服器 Control。 控制項必須實作 ICallbackEventHandler 介面並提供 RaiseCallbackEvent(String) 方法。

argument
String

從用戶端指令碼傳遞到伺服器的引數

RaiseCallbackEvent(String) 方法。

clientCallback
String

會接收成功的伺服器事件結果的用戶端事件處理常式名稱。

context
String

在啟始回呼 (Callback) 之前,於用戶端上評估的用戶端指令碼。 指令碼的結果會傳回給用戶端事件處理常式。

useAsync
Boolean

true 表示非同步執行回呼,false 表示同步執行回呼。

傳回

叫用用戶端回呼的用戶端函式名稱。

例外狀況

指定的 Controlnull

備註

此方法的 GetCallbackEventReference 這個多載需要參數 useAsync ,這可讓您將 值設定為 true ,以非同步方式執行用戶端回呼。 這個方法的多載版本,預設不需要 useAsync 參數將值設定為 false

如需此方法的詳細資訊,請參閱多載 GetCallbackEventReference 方法的備註。

另請參閱

適用於

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

取得用戶端函式的參考,這個函式會在叫用時,啟始對伺服器事件的用戶端回呼。 這個多載方法的用戶端函式包含指定的目標、引數、用戶端指令碼、內容、錯誤處理常式和布林值。

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

參數

target
String

處理用戶端回呼之伺服器 Control 的名稱。 控制項必須實作 ICallbackEventHandler 介面並提供 RaiseCallbackEvent(String) 方法。

argument
String

從用戶端指令碼傳遞到伺服器的引數

RaiseCallbackEvent(String) 方法。

clientCallback
String

會接收成功的伺服器事件結果的用戶端事件處理常式名稱。

context
String

在啟始回呼 (Callback) 之前,於用戶端上評估的用戶端指令碼。 指令碼的結果會傳回給用戶端事件處理常式。

clientErrorCallback
String

當伺服器事件處理常式發生錯誤時,接收結果之用戶端事件處理常式的名稱。

useAsync
Boolean

true 表示非同步執行回呼,false 表示同步執行回呼。

傳回

叫用用戶端回呼的用戶端函式名稱。

範例

下列程式碼範例示範如何在遞增整數的用戶端回呼案例中使用 方法的 GetCallbackEventReference 兩個多載。

顯示兩個回呼機制;它們之間的差異是使用 context 參數。 ReceiveServerData1用戶端回呼函式是使用 context 參數來提供。 相反地, ReceiveServerData2 用戶端回呼函式是在頁面上的 <script> 區塊中定義。 方法是 RaiseCallbackEvent 伺服器處理常式,它會遞增傳遞給它的值,而 GetCallbackResult 方法會以字串的形式傳回遞增的值。 RaiseCallbackEvent如果方法傳回錯誤,則會呼叫用戶端函式 ProcessCallBackError

<%@ 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>

備註

此方法的 GetCallbackEventReference 這個多載會採用 target 字串參數,而不是 Control 參數。 當您想要回呼回到包含 UniqueID 控制項的字串以外的專案時,請使用這個多載。

此外,此方法的 GetCallbackEventReference 這個多載需要 useAsyncclientErrorCallback 參數。 參數 useAsync 可讓您將 值設定為 true ,以非同步方式執行用戶端回呼。 這個方法的多載版本,預設不需要 useAsync 參數將值設定為 false 。 參數 clientErrorCallback 可讓您定義如果伺服器處理常式 RaiseCallbackEvent 方法傳回錯誤時所呼叫的用戶端函式名稱。 這個方法的多載版本,不需要 clientErrorCallback 參數將值設定為 null。

如需此方法的詳細資訊,請參閱多載 GetCallbackEventReference 方法的備註。

另請參閱

適用於

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

取得用戶端函式的參考,這個函式會在叫用時,啟始對伺服器事件的用戶端回呼。 這個多載方法的用戶端函式包含指定的控制項、引數、用戶端指令碼、內容、錯誤處理常式和布林值。

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

參數

control
Control

處理用戶端回呼的伺服器 Control。 控制項必須實作 ICallbackEventHandler 介面並提供 RaiseCallbackEvent(String) 方法。

argument
String

從用戶端指令碼傳遞到伺服器 RaiseCallbackEvent(String) 方法的引數。

clientCallback
String

會接收成功的伺服器事件結果的用戶端事件處理常式名稱。

context
String

在啟始回呼 (Callback) 之前,於用戶端上評估的用戶端指令碼。 指令碼的結果會傳回給用戶端事件處理常式。

clientErrorCallback
String

當伺服器事件處理常式發生錯誤時,接收結果之用戶端事件處理常式的名稱。

useAsync
Boolean

true 表示非同步執行回呼,false 表示同步執行回呼。

傳回

叫用用戶端回呼的用戶端函式名稱。

例外狀況

指定的 Controlnull

備註

此方法的 GetCallbackEventReference 這個多載需要 useAsyncclientErrorCallback 參數。 參數 useAsync 可讓您將 值設定為 true ,以非同步方式執行用戶端回呼。 這個方法的多載版本,預設不需要 useAsync 參數將值設定為 false 。 參數 clientErrorCallback 可讓您定義如果伺服器處理常式 () 方法傳 RaiseCallbackEvent 回錯誤時所呼叫的用戶端函式名稱。 這個方法的多載版本,不需要 clientErrorCallback 參數將值設定為 null。

如需此方法的詳細資訊,請參閱多載 GetCallbackEventReference 方法的備註。

另請參閱

適用於