Click here to Skip to main content
14,177,305 members
Rate this:
Please Sign up or sign in to vote.
I am using PageMethods to call server side method from client side but I am getting a problem that server side method is calling only if, I am calling the method from source part, if i am making a javascript file with the same javascript code and adding the link into the page then it is not working, only PageMthods is not working but all other thing of javascript file is working fine.

Please suggest how would I resolve this issue.

Updated 14-Feb-19 22:44pm
Ankur\m/ 4-Apr-13 5:26am
My first guess would be - the URL isn't correct. Can you show your javascript code which is calling the pagemethod?
JoCodes 14-Oct-13 12:53pm
post your code which you tried?
sri senthil kumar 4-Apr-13 8:23am
Check this url for basic page method call syntax

Also post your code so that we could help you...
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

try this.. :)


function GetName() {

        type: "POST",
        url: "Default.aspx/GetData", //Pagename/Functionname
        contentType: "application/json;charset=utf-8",
        data: {},//data
        dataType: "json",
        success: function (data) {


        error: function (result) {




<span onclick="GetName()">Call Web Method</span>


      public static string GetData()
          string name= "My name is Nirav Prabtani";

          return name;
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

Hi Friend,

It should not affect weather keeping script in page level or in script file.
Check once weather you gave right file or any other syntax.

it is good to find the error with Firebug..!
Rate this: bad
Please Sign up or sign in to vote.

Solution 5

Below given code worked for me.

.cs -

using Microsoft.AspNet.FriendlyUrls;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)


    [System.Web.Services.WebMethod(EnableSession = true)] 
    [System.Web.Script.Services.ScriptMethod(UseHttpGet = false, ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
    public static string yourmethod1()
         return "Allow user";

apsx.cs Page -

<%@ Page Language="C#" AutoEventWireup="false" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">

<head runat="server">


     <script type="text/javascript">

        function GreetingsFromServer()
            PageMethods.yourmethod1(OnSuccess, OnError)
        function OnSuccess(response)
        function OnError(error) 



    <form id="form1" runat="server"  method="post" >

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

            <input id="Button1" type="button" value="button" onclick=" return GreetingsFromServer();" />



Web.conf -


           <add key="owin:AutomaticAppStartup" value="false" />


            <compilation debug="true" targetFramework="4.5.2" />

            <httpRuntime targetFramework="4.5.2" />

                       <allow users="*"/>



This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web04 | 2.8.190526.1 | Last Updated 15 Feb 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100