asp.net page methods returning undefined

浪尽此生 提交于 2020-01-05 03:10:13

问题


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?


回答1:


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.




回答2:


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);
 }


来源:https://stackoverflow.com/questions/223308/asp-net-page-methods-returning-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!