Call WebMethod from other ASPX page using jQuery AJAX

Last Reply 9 months ago By dharmendr

Posted 9 months ago

if webmethod is also on another aspx page.

want to call webmethod public function from another aspx page

Posted 9 months ago

Hi mukesh1,

Yes it is possible. For this you need to specify correct URL. Check the below example.

In the below example i have a WebMethod GetCurrentTime which is in Default page and i am calling the WebMethod in CS page.



    Your Name :
    <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
    <input id="btnGetTime" type="button" value="Show Current Time" onclick="ShowCurrentTime()" />
<script type="text/javascript" src=""></script>
<script type="text/javascript">
    function ShowCurrentTime() {
            type: "POST",
            url: "Default.aspx/GetCurrentTime", // Specify the WebMethod page url
            data: '{name: "' + $("#txtUserName").val() + '" }',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) { alert(response.d); },
            error: function (response) { alert(responseresponseText); },
            failure: function (response) { alert(response.d); }



public static string GetCurrentTime(string name)
    return "Hello " + name + Environment.NewLine + "The Current Time is: " + DateTime.Now.ToString();