Monday, September 18, 2006

Corrections of ClientCallBack Example

I have tested the example of ASP.NET 2.0 new feature - ClientCallBack at ASP.NET 2.0's Client Callback Feature, but found not working due to:

1. There is no this.GetCallbackEventReference()
2. RaiseCallbackEvent() does not return string data type, from ICallbackEventHandler
3. Missing of GetCallbackResult(), that defined in ICallbackEventHandler


Finally I get it done by making some corrections:

1. Use this.ClientScript.GetCallbackEventReference()
2. Define the RaiseCallbackEvent() that returns no data type
3. Define GetCallbackResult() to return the result to the client-side


Corrected code:

protected void Page_Load(object sender, EventArgs e)
{
       sCallBackInvocation = this.ClientScript.GetCallbackEventReference(this, "message", "ShowServerTime", "context", "OnError",true);
}

public void RaiseCallbackEvent(string eventArgument)
{
       sCallBackInvocation = DateTime.Now.ToString();
}

public string GetCallbackResult()
{
       return sCallBackInvocation;
}



Recommendation
1. Check whether the browser does support callback feature in Page_Load() event


if (!Request.Browser.SupportsCallback)
    // error message

No comments: