Javascript 我的PageMethods从未在.NET中访问过
我什么都试过了,什么都没用。PageMethods永远无法访问,但是调用之前的一切都很好。这可能是隐藏在代码中的东西吗?我怀疑我在整个项目上做错了什么。这可能是我必须放在页面母版中的东西吗Javascript 我的PageMethods从未在.NET中访问过,javascript,asp.net,Javascript,Asp.net,我什么都试过了,什么都没用。PageMethods永远无法访问,但是调用之前的一切都很好。这可能是隐藏在代码中的东西吗?我怀疑我在整个项目上做错了什么。这可能是我必须放在页面母版中的东西吗 public class GetElements { [ScriptMethod, WebMethod] public static string[] getTargets() { //List<string> tar
public class GetElements
{
[ScriptMethod, WebMethod]
public static string[] getTargets()
{
//List<string> targetList = new List<string>();
string[] targetList = new string[2];
targetList[0] = "poo";
targetList[1] = "bar";
foreach (Target t in PbcXml.oDeserialized.oTargetList)
{
}
return targetList;
}
}
aspx页面:
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
我相信您只需要在静态方法上使用WebMethod属性。。。我已经有一段时间没有使用PageMethod了。此外,您还可以在非WebForms页面的其他类上定义page方法。您需要在将调用它的ASP.NET WebForms页面上定义它。我认为这就是问题所在 如果在尝试上述操作后仍然无法工作,请加载浏览器的Javascript控制台以查看您遇到的Javascript错误,并运行一个免费工具(如Fiddler),以查看在没有JS错误的情况下web请求的情况
希望这能有所帮助。使用这种方法,您到底想做什么?
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>