Thursday, February 5, 2009

How to implement ICallbackEventHandler

-------- code behind---------
public partial class Home : System.Web.UI.Page, ICallbackEventHandler
{
public string sCallBackFunctionInvocation;
sCallBackFunctionInvocation = this.ClientScript.GetCallbackEventReference(this, "sId", "CallBackReturnFunction", "oContext", "OnCallBackError",false) + ";";
}

protected string returnValue;
public string GetCallbackResult()
{
return returnValue;
//throw new Exception("The method or operation is not implemented.");
}

public void RaiseCallbackEvent(string eventArgument)
{
//throw new Exception("The method or operation is not implemented.");
try
{
returnValue = //retrieve data from argument
}
catch (Exception ex)
{
ErrolLogController.LogError(ex.Message);
}
}






--------- Javascript---------------

function clickEv()
{
var sId = id;
var oContext = new Object();
<%=sCallBackFunctionInvocation%>
}

function CallBackReturnFunction(sReturnValue, oContext)
{
//do inner HTML setup
}

function OnCallBackError(exception,context)
{
alert(exception);
}

No comments: