이 항목은 아직 평가되지 않았습니다.- 이 항목 평가

ClientScriptManager.GetCallbackEventReference 메서드 (String, String, String, String, String, Boolean)

참고: 이 메서드는 .NET Framework 버전 2.0에서 새로 추가되었습니다.

호출될 경우 클라이언트에서 서버측 이벤트를 다시 호출하도록 하는 클라이언트측 함수에 대한 참조를 가져옵니다. 이 오버로드된 메서드의 클라이언트측 함수에는 지정한 대상, 인수, 클라이언트측 스크립트, 컨텍스트, 오류 처리기 및 부울 값이 포함됩니다.

네임스페이스: System.Web.UI
어셈블리: System.Web(system.web.dll)

public string GetCallbackEventReference (
	string target,
	string argument,
	string clientCallback,
	string context,
	string clientErrorCallback,
	bool useAsync
)
public String GetCallbackEventReference (
	String target, 
	String argument, 
	String clientCallback, 
	String context, 
	String clientErrorCallback, 
	boolean useAsync
)
public function GetCallbackEventReference (
	target : String, 
	argument : String, 
	clientCallback : String, 
	context : String, 
	clientErrorCallback : String, 
	useAsync : boolean
) : String

매개 변수

target

클라이언트 콜백을 처리하는 서버 Control의 이름입니다. 이 컨트롤에서는 ICallbackEventHandler 인터페이스를 구현하고 RaiseCallbackEvent 메서드를 제공해야 합니다.

argument

클라이언트측 스크립트에서 서버측으로 전달되는 인수입니다.

RaiseCallbackEvent 메서드입니다.

clientCallback

성공한 서버측 이벤트의 결과를 받는 클라이언트측 이벤트 처리기의 이름입니다.

context

콜백을 시작하기 전에 클라이언트에서 계산되는 클라이언트측 스크립트입니다. 스크립트 결과는 클라이언트측 이벤트 처리기로 다시 전달됩니다.

clientErrorCallback

서버측 이벤트 처리기에서 오류가 발생할 때 결과를 받는 클라이언트측 이벤트 처리기의 이름입니다.

useAsync

콜백을 동기적으로 수행하려면 true이고, 비동기적으로 수행하려면 false입니다.

반환 값

클라이언트 콜백을 호출하는 클라이언트측 함수의 이름입니다.

GetCallbackEventReference 메서드의 이 오버로드는 Control 매개 변수 대신 target 문자열 매개 변수를 사용합니다. 컨트롤의 UniqueID가 들어 있는 문자열이 아닌 다른 문자열로 콜백을 이동하려는 경우 이 오버로드를 사용합니다.

또한 GetCallbackEventReference 메서드의 이 오버로드에는 useAsyncclientErrorCallback 매개 변수가 필요합니다. useAsync 매개 변수의 값을 true로 설정하면 클라이언트 콜백을 비동기적으로 수행할 수 있습니다. useAsync 매개 변수가 필요 없는 이 메서드의 오버로드 버전은 기본적으로 이 매개 변수 값을 false로 설정합니다. clientErrorCallback 매개 변수를 사용하면 서버측 처리기인 RaiseCallbackEvent 메서드에서 오류를 반환하는 경우 호출되는 클라이언트측 함수의 이름을 정의할 수 있습니다. clientErrorCallback 매개 변수가 필요하지 않은 이 메서드의 오버로드 버전은 이 매개 변수 값을 null로 설정합니다.

이 메서드에 대한 자세한 내용은 오버로드 GetCallbackEventReference 메서드의 설명 부분을 참조하십시오.

다음 코드 예제에서는 클라이언트측 콜백 시나리오에서 정수를 증가시키는 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>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

.NET Framework

2.0에서 지원
이 정보가 도움이 되었습니까?
(1500자 남음)
커뮤니티 콘텐츠 추가