Search code examples
c#javascriptasp.netserver-side

0x800a1391 - JavaScript runtime error: 'PageMethods' is undefined


I need to call server side code "c# Function" in my asp.net project in javascript so i used this way:

<script type="text/javascript">

    function doReadPublicData() {
        PageMethods.btnVerifyPubData_Click(OnGetMessageSuccess, OnGetMessageFailure);
    }

    function OnGetMessageSuccess(result, userContext, methodName) {
        alert(result);
    }

    function OnGetMessageFailure(error, userContext, methodName) {
        alert(error.get_message());
    }
</script>

And I enabled the EnablePageMethods property in the script manager:

<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">
</asp:ScriptManager>

<asp:Button ID="btnVerifyPubData" runat="server" OnClientClick="doReadPublicData();"
    OnClick="btnVerifyPubData_Click" Text="Show Information"
    CssClass="submitButton" PostBackUrl="~/ParsePublicData.aspx" />

But this error occurs.


Solution

  • solved finally .. I have to add "static" to my web method to work successfully ! :

    [WebMethod]
        public static void btnVerifyPubData_Jscript(string t)
        {
    
        }