Search code examples
javascriptvb.netpagemethods

Why is PageMethods object undefined?


I've read several answers to similar questions and none of them answer my question. I've tried everything I can think of. Here's what my code looks like:

<asp:ScriptManager ID="ScriptMgr" runat="server" EnablePageMethods="true"></asp:ScriptManager>
<asp:TextBox ID="TextBox" runat="server" onblur="textboxOnBlur()"></asp:TextBox>
<script>
     function onSuccess() {
        alert("success");
    }

    function onFailure() {
        alert("failure");
    }

    function textboxOnBlur() {
        PageMethods.CheckDBForCodes(onSuccess, onFailure);
        //alert("test");
    }

</script>

Here's the server-side function that should be called by PageMethods:

 <System.Web.Services.WebMethod()>
Protected Shared Sub CheckDBForCodes() 
    `search DB for codes
End Sub

For some reason, I'm still getting the error message that says that PageMethods is undefined. As you can see, the textboxOnBlur function is called when you click away from the textbox. Am I missing something?


Solution

  • The reason why the PageMethods object was undefined was because the access modifier to the server side function was set to Protected. I changed it to Public and all was well with the world.