[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 864
  • 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
berechit
Asked:
berechit
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 ReddyCommented:
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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