I need to call ASP.Net server side code from the client. Because I'm in an ascx user control I can't use [webmethod] + PageMethods as this only works on ASPX pages.
The next option that I thought would work was manually creating a client-callback. Using this method the client will successfully call the server code but the client will not get the call back. This is my code for setting up the client side script blocks:
protected void Page_Load(object sender, EventArgs e)
{
String strJSCallbackPrefix = this.ClientID;
ClientScriptManager cm = Page.ClientScript;
String cbReference = cm.GetCallbackEventReference(this, "arg", strJSCallbackPrefix + "ReceiveServerData", "context");
String callbackScript = "function " + strJSCallbackPrefix + "CallServer(arg, context){" + cbReference + "; }";
cm.RegisterClientScriptBlock(this.GetType(), strJSCallbackPrefix + "CallServer", callbackScript, true);
String strReceiveServerData = "function " + strJSCallbackPrefix + "ReceiveServerData(arg, context){document.getElementById('btnCancel').value='thisandthat';}";
cm.RegisterClientScriptBlock(this.GetType(), strJSCallbackPrefix + "ReceiveServerData", strReceiveServerData, true);
Button2.OnClientClick = strJSCallbackPrefix + "CallServer('test message',1); " + "return false;";
}
public string GetCallbackResult()
{
return returnValue;
}
public void RaiseCallbackEvent(string eventArgument)
{
returnValue = "11223" + eventArgument;
}
Does anyone have any ideas why the client call back is not getting fired?