问题描述
我看,我只能在同一时间假设工作过的一些旧的code。
I'm looking at some old code that I can only assume worked at one time.
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" />
后面的 code:
[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()
在第一个片段,铬报道:
But at the call to PageMethods.GetCompanyList()
in the first snippet, Chrome reports:
PageMethods没有定义
有人能看到发生了什么变化,以prevent这从工作?
Can anyone see what has changed to prevent this from working?
注:我发现类似的问题,但他们似乎都与此相关的code不工作的母版页或用户控件,这不是这里的情况的
推荐答案
<$c$c>EnablePageMethods$c$c>实际上只有一个页
子类的方法进行交互是公开
,静态
,并归结为一个的WebMethod
。
EnablePageMethods
actually only interacts with methods of a Page
subclass that are public
, static
, and attributed as a WebMethod
.
GetCompanyList
有2那些,只是也需要静态
。
GetCompanyList
has 2 of those and just also needs to be static
.
[System.Web.Services.WebMethod()]
[System.Web.Script.Services.ScriptMethod()]
public static IEnumerable<CompanyMinimum> GetCompanyList(int officeId) {
// ...
}
和,我怀疑这是怎么回事的是,它的离开 PageMethods
不确定的客户端,如果它没有找到有所有3的任何方法。
And, I suspect what's happening is that it's leaving PageMethods
undefined client-side if it doesn't find any methods that have all 3.
这篇关于PageMethods没有在ASPX页面中定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!