locked
PageMethods revisited... RRS feed

  • Question

  • User1583495713 posted

    Hi,

    I've red the entire thread : PageMethods and now I'm here with this issue that PageMethods is undefined or today after 9 years there's an error message in Visual Studio 2013 Community saying Cannot find name 'PageMethods'.  The image below is showing the error and this is a Typescript file but I tried a .JS directly and I get the same problem

    http://1drv.ms/1ze8nJr

    The ASPX has the ScriptManager, it has the EnablePageMethods="true", the method is public static with the WebMethod attribute as it should and the javascript is added in the header so I really don't see why PageMethods isn't recognized in JS

    Thursday, January 29, 2015 5:44 AM

All replies

  • User-271186128 posted

    Hi GearWord,

    According to your description, I create a sample using the following code. It seems that everything worked well. You could refer to it.

        <script type="text/javascript">
            function Myfunction(e) {
                e.preventDefault();
                var str = PageMethods.SendValues("AAA", OnSuccess);
            };
    
            function OnSuccess(response, userContext, methodName) {
                alert(response);
            }
        </script>
    
            <asp:Button ID="Button1" runat="server" OnClientClick="Myfunction(event);" Text="Button" />
            <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server"></asp:ScriptManager>

    Code Behind:

            [WebMethod]
            public static string SendValues(string name)
            {
                return "Hello " + name;
            }

    Note: I also use Visual Studio 2013.

    Best Regards,
    Dillion

    Friday, January 30, 2015 12:54 AM
  • User1583495713 posted

    Hi,

    Well I did the same over here and yet the PageMethods is undefined.  It simply doesn't exist at all.  Where is this class located ? Do I miss a reference somehow ?  I'm not sure because everything else works perfectly except PageMethods doesn't exist

    I have the reference System.Web.Extensions

    http://1drv.ms/1EtVBv5

    Friday, January 30, 2015 7:18 AM
  • User1583495713 posted

    I see it works in the script directly inside the aspx markup however the original message states that it's from a .TS or let say a .JS that the PageMethods is undefined and doesn't exist.
    Now believe it or not I created the method like your Myfunction and tried to call Myfunction from the .TS file or the .JS file if you whish and nope it doesn't see it at all.  It's like everything I declare in a script inside the aspx markup isn't available to .TS or .JS file

    Friday, January 30, 2015 7:21 AM
  • User1583495713 posted

    I miss Silverlight..........

    Friday, January 30, 2015 7:24 AM