From this example we can call back server from JavaScript without post back , but i want to make CallServer method to return the result and i try it as below
string callBackReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "function(result) {alert(result);response = result;}", "context", "function(result) {response = 'Err';}", true);
string callbackScript = "function CallServer(arg, context) { var response; " + callBackReference + "; return response;}";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true);
and in JavaScript i do the below
response = CallServer("username", "");
alert("response:" + response);
always response equal undefined although i make it asynchronous ...
Could any help me in finding a solution for such a problem ?
NOTE:
My main problem that lead me to try the above solution that my need to call 'CallServer' method in OnClientClick
of Asp button and return true or false as below
<asp:Button ID="Button1" runat="server" Text="Button"
OnClientClick="return CallServer('arg','');" onclick="Button1_Click" />