以下是我对服务器端方法的PageMethod调用的实现。它当前正在生成此错误消息“未捕获的ReferenceError:未定义PageMethod”。我可以在Chrome Javascript控制台中看到此错误。我的研究表明,PageMethods最常见的问题是忘记将EnablePageMethods设置为“true”(这样做)并且需要重建应用程序(也是这样)。我现在很难过。谁能发现我做错了什么?
脚本管理器:
<telerik:RadScriptManager ID="RadScriptManager1" runat="server" EnablePageMethods="true">
ASPX:
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
function confirmCallBackFn(arg) {
if (arg == true) {
var firstDataItem = $find("<%=RadGrid1.ClientID %>").get_masterTableView().get_dataItems()[0];
var PackageID = firstDataItem.getDataKeyValue("PackageID");
PageMethod.RemovePackagePageMethod(PackageID);
}
else {
}
}
</script>
</telerik:RadCodeBlock>
代码背后:
[WebMethod()]
public static void RemovePackagePageMethod(int PackageID)
{
Inventory inv = new Inventory();
inv.RemovePackage(PackageID);
}
public void RemovePackage(int PackageID)
{
SBMData2.SBMDataContext db = new SBMData2.SBMDataContext();
var boxes = from p in db.Packages
where p.PackageID == PackageID
select p;
foreach (var box in boxes)
{
db.Packages.DeleteOnSubmit(box);
}
try
{
db.SubmitChanges();
RadGrid1.Rebind();
}
catch (Exception ex)
{
RadWindowManager1.RadAlert("System error deleting package", 200, 200, "exception", null);
}
}
d
答案 0 :(得分:4)
试
PageMethods.RemovePackagePageMethod(PackageID);
(使用 s - PageMethods而不是PageMethod)