PageMethods not defined

2019-07-04 01:46发布

问题:

I have a page with a MasterPage, in the master page, I have this:

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

And I have this method in the code behind:

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

And then I have this javascript function:

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

But when I click on the link to make everything work, I get this error:

Uncaught ReferenceError: PageMethods is not defined

回答1:

PageMethods are not supported in master pages and user controls.