I am trying to use page methods in my asp.net page. I have enable page methods set to true on the script manager, the webmethod attribute defined on the method, the function is public static string, I know the function works because when I run it from my code behind it generates the expected result, but when I call it via page method in my result function the result is always alerted as undefined. If I use fiddler it doesn't even look like there is additional traffic or a new request created. I'm running the site on port 82 if that makes a difference. I'm at a loss here. Can someone give me some pointers?
A:
OK, stupid me. Here is some code.
function getName()
{
var ddlAdCodes=$get('<%=ddlAdCodes.ClientID %>');
var value=ddlAdCodes.options[ddlAdCodes.selectedIndex].value;
//alert(value);
PageMethods.getAdCodeInfo(value,onSuccess(),onError());
}
function onSuccess(result)
{
alert(result);
}
function onError(error)
{
alert("error "+error);
}
Chris Westbrook
2008-10-21 20:52:07
Next time hit the "Code Sample" button (101010) to format it nicely and make it easier to read.
Kon
2008-10-21 21:09:00
+1
A:
In your PagesMethods call, remove the parentheses from the callback and error functions:
PageMethods.getAdCodeInfo(value, onSuccess, onError)
onSuccess
and onError
are basically variables that point to the functions. So you don't need parentheses for variable names.
Kon
2008-10-21 21:07:48
A:
I found one very good article on pagemethod, which can be of use
http://aspdotnetmatters.blogspot.com/2010/08/page-methods.html
ashish
2010-10-14 08:22:25