PageMethods未定义

Nah*_*uel 3 javascript asp.net ajax pagemethods

我有一个带有MasterPage的页面,在母版页中,我有这个:

 <ajaxToolkit:ToolkitScriptManager ID="scriptManager" 
                                   runat="server" 
                                   AsyncPostBackTimeout="99999999"
                                   EnablePageMethods="true" />
Run Code Online (Sandbox Code Playgroud)

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

[WebMethod]
public void SavePreference(string graphVersion)
{
    //some code here
}
Run Code Online (Sandbox Code Playgroud)

然后我有这个javascript函数:

 function lnkLearnHardWayclick(){ 
    if( $("#chkDontShowAgain").attr("checked") == "checked")
    {
        PageMethods.SavePreference('new');
    }
    $("#info").hide();
    $("#hardWay").show();
}
Run Code Online (Sandbox Code Playgroud)

但是,当我点击链接以使一切正常时,我收到此错误:

未捕获的ReferenceError:未定义PageMethods

Cha*_*mal 6

PageMethods 主页和用户控件不支持.

  • 嗯...... WebMethod必须是静态的.不管怎么说,多谢拉! (3认同)