我在看一些老代码,我只能假设它曾经起过作用。
MyPage.aspx:
function GetCompanyList(officeId) {
var companyList = document.getElementById('<%= CompanyDropDown.ClientID %>');
if (companyList.length == 0)
PageMethods.GetCompanyList(officeId, OnGetCompanyList);
else
EditCompany();
}和:
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />代码背后:
[System.Web.Services.WebMethod()]
[System.Web.Script.Services.ScriptMethod()]
public IEnumerable<CompanyMinimum> GetCompanyList(int officeId) {
return (
from c in Repository.Query<Company>()
where !c.IsDeleted && c.TypeEnumIndex == (short)CompanyRelationshipType.Hotel
select new CompanyMinimum() {
id = c.Id,
desc = c.Description
}
).ToList();
}但在第一段对PageMethods.GetCompanyList()的调用中,Chrome报告说:
未定义PageMethods
有谁能看出是什么改变了才能阻止它发挥作用呢?
注意:我发现了类似的问题,但这些问题似乎都与这段代码不适用于母版页或用户控件有关,这里的情况并非如此。
发布于 2013-08-14 21:17:24
实际上,EnablePageMethods只与Page子类的方法交互,这些子类是public、static,并被归为WebMethod。
GetCompanyList有两个这样的功能,而且也需要是static。
[System.Web.Services.WebMethod()]
[System.Web.Script.Services.ScriptMethod()]
public static IEnumerable<CompanyMinimum> GetCompanyList(int officeId) {
// ...
}而且,我怀疑如果PageMethods没有找到所有3种方法的话,它就会留下未定义的客户端。
发布于 2013-08-14 21:09:15
您可以通过ASP.NET调用jQuery AJAX页面方法,如下所示:
$.ajax({
type: "POST",
url: "PageName.aspx/MethodName",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// Do something interesting here.
}
});发布于 2013-10-04 19:58:43
也许你是在你的页面中使用路由。然后必须在调用PageMethods之后设置真实路径:
PageMethods.set_path("<%=ResolveUrl("~/YourPage.aspx")%>");
PageMethods.YourMethod(param, OnSuccess, OnError);https://stackoverflow.com/questions/18242334
复制相似问题