PageMethods未定义。

3

我有一个带有MasterPage的页面,在MasterPage中,我有以下内容:

 <ajaxToolkit:ToolkitScriptManager ID="scriptManager" 
                                   runat="server" 
                                   AsyncPostBackTimeout="99999999"
                                   EnablePageMethods="true" />

我在后台代码中有这个方法:

[WebMethod]
public void SavePreference(string graphVersion)
{
    //some code here
}

然后我有这个JavaScript函数:
 function lnkLearnHardWayclick(){ 
    if( $("#chkDontShowAgain").attr("checked") == "checked")
    {
        PageMethods.SavePreference('new');
    }
    $("#info").hide();
    $("#hardWay").show();
}

但是当我点击链接使一切运作时,出现了这个错误:

未捕获的引用错误:PageMethods未定义

1个回答

6

PageMethods 不支持在母版页和用户控件中使用。


我不明白...所以我必须把ToolScriptManager放在我想要进行PageMethods的页面中吗?因为所有的Javascript代码和后台代码都在example.aspx中(例如)。 - Nahuel
将您的页面方法放入.aspx.cs文件中。 - Chamika Sandamal
是的,我有它在这里...事实上,我的工作伙伴在另一个页面中完成了一部分,并且运行正常...我不知道为什么它对我不起作用。 - Nahuel
3
嗯……就是WebMethod必须是静态的呵呵。无论如何还是谢谢! - Nahuel

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接