简体   繁体   English

asp.net页面方法返回未定义

[英]asp.net page methods returning undefined

I am trying to use page methods in my asp.net page. 我正在尝试在asp.net页面中使用页面方法。 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. 我已在脚本管理器上将启用页面方法设置为true,在该方法上定义了webmethod属性,该函数是公共静态字符串,我知道该函数有效,因为当我从其背后的代码运行它时会产生预期的结果,但是当我在结果函数中通过页面方法调用它,结果总是被警告为未定义。 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. 如果有区别,我将在端口82上运行该站点。 I'm at a loss here. 我在这里茫然。 Can someone give me some pointers? 有人可以给我一些指示吗?

In your PagesMethods call, remove the parentheses from the callback and error functions: 在您的PagesMethods调用中,从回调和错误函数中删除括号:

PageMethods.getAdCodeInfo(value, onSuccess, onError)

onSuccess and onError are basically variables that point to the functions. onSuccessonError基本上是指向函数的变量。 So you don't need parentheses for variable names. 因此,变量名称不需要括号。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM