• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 879
  • Last Modified:

PageMethods c#

I have one project that I use PageMethods many times and works fine.

I started a new projetc and PageMethods does not work. It say:" PageMethods is not definied"

In the project that works my code is something like that:

Server code:

Public Sub Log()

end sub

And Javascript code:

PageMethods.Log();

My Scriptmanages is:

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

Anyone has any idea about this ?
0
Anderson Meneses
Asked:
Anderson Meneses
3 Solutions
 
masterpassCommented:
Please refer to this article

http://www.experts-exchange.com/Programming/Languages/Scripting/AJAX/A_2575-NET-AJAX-callbacks-to-ASPX-Pages.html

The main things to watch out is ..

1. The page method should be static
2. The method should be annotated with webmethod and script method

Hope this helps :)
0
 
Dominic AbrahamSr.Software EngineerCommented:
Hi
As in previous reply,
The page method should be static and should have [System.Web.Services.WebMethod]    attribute.
You will get a good details about the pagemethod usage from the below link

PageMethod

And check whether you have references to
<%@ Register Assembly="System.Web.Extensions,...... %> in your your page


Regards
Dominic
0
 
Roopesh ReddyIT AnalystCommented:
Hi,

I installed latest version of AJAX Control Toolkit from Nuget and tried creating a sample app.

It's working fine for me!

<ajaxToolkit:ToolkitScriptManager runat="server" ID="scriptManager1" EnablePageMethods="true">
    </ajaxToolkit:ToolkitScriptManager>

    <input type="button" name="btn" value="Click" onclick="PageMethods.HelloWorld(OnSuccess,OnFailure);" />

    <script type="text/javascript">
        function OnSuccess(result) {
            alert(result);
        }

        function OnFailure(error) {
            alert(error);
        }
    </script>

[WebMethod]
        public static string HelloWorld()
        {
            return "Hello World";
        }

Open in new window


Hope it helps u...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now