Martin Smellworse
Martin Smellworse

Reputation: 1752

What does PageMethods actually return?

This code gets the return value from public static string in the code behind and shows what is returned in an alert.

<script type="text/javascript"> 
function GetFromServer() 
{ 
PageMethods.GetHello(OnGetHelloComplete);
} 
function OnGetHelloComplete(result, userContext, methodName)
{
alert("Result: " + result + "\n" + 
"Context: " + userContext + "\n" + 
"Method name: " + methodName); 
} 
</script>

The web method in the code behind is a public static string. But what is it returning?

Why can't I write ...

var myString = PageMethods.GetHello()

Where are 'result' and 'userContext' and 'methodName' appearing from?

EDIT: Please ignore, I had a look at the source and saw what is being output there.

Upvotes: 0

Views: 85

Answers (1)

Konstantin Dinev
Konstantin Dinev

Reputation: 34895

GetHello invokes a call to the server and OnGetHelloComplete is a callback to be executed when the request is complete and the parameters are being populated.

Upvotes: 2

Related Questions