How do you use the server side return value (VB.NET) on the client side (JavaScript)?

Is it possible to call a server-side function from the client side using PageMethods and access this function in JavaScript? Here is an example:

Client side:

 function onBlur(){ //this function is called when you click away from a textbox PageMethods.SomeServerSideFunction(params, onSuccess, onFailure); } function onSuccess(){ //do something on success //I want to be able to print out the server side function return value here alert(PageMethods.DoesItWork(params)) //this is what I've tried, but it doesn't work } function onFailure(){ //do something on failure } 

Server side:

 <System.Web.Services.WebMethod()> Public Shared Function DoesItWork(params As String) As Boolean 'logic to determine a return value Dim RetVal as Boolean Return RetVal 'I want to be able to use this return value on the client side End Function 

Simply put, I just need to have access to the return value of the function on the server side on the client side. Thanks in advance.

+1
javascript pagemethods
source share
1 answer

Stolen from an online tutorial, but basically you do it:

 [System.Web.Services.WebMethod] public static string ToUpper(string data) { return data.ToUpper(); } 

-

 function CallMethod() { PageMethods.ToUpper("hello", OnSuccessCallback, OnFailureCallback); } function OnSuccessCallback(res) { alert(res); } function OnFailureCallback() { alert('Error'); } 
+2
source share

All Articles