Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7780423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:53:35+00:00 2026-06-01T18:53:35+00:00

Is it possible to call a method attributed with [WebMethod] from javascript on a

  • 0

Is it possible to call a method attributed with [WebMethod] from javascript on a different page? I.e. using the following jquery ajax call from script on a page called PageTwo.aspx:

    $.ajax(
        {
            type: "POST",
            url: "pageone.aspx/PageOneMethodOne",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg)
                     {
                        //something
                     }
        }
    );

PageOne.aspx.cs containing

    [WebMethod]
    public string PageOneMethodOne()
    {
        return "hello world";
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:53:37+00:00Added an answer on June 1, 2026 at 6:53 pm

    This is possible, as long as you specify the correct URL. Check out the following form:

    <form id="form1" runat="server">
    <div>
        <div id="messages">
        </div>
        <input type="text" id="echo" /><input id="echoSubmit" value="Echo!" type="button"/>
    </div>
    

    and it’s corresponding Javascript:

    <script type="text/javascript">
        $(function () {
            $('#echoSubmit').click(function () {
                var mes = $('#echo').val();
                var jsonText = JSON.stringify({ message: mes });
    
                $.ajax({
                    type: "POST",
                    url: "SampleForm.aspx/SendMessage",
                    data: jsonText,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (msg) {
                        $("#messages").append(msg.d);
                    }
                });
            });
        });
    </script>
    

    Clicking the echoSumbit button will send the contents of the input box to a WebMethod on another control, SampleForm.aspx. Here is the code-behind of that form:

    public partial class SampleForm : System.Web.UI.Page
    {
        [WebMethod]
        public static string SendMessage(string message)
        {
            return message;
        }
    }
    

    The click handler in Chat.aspx sends the input value to SampleForm.aspx.cs, which returns the sent value. The returned value is appended to a div in Chat.aspx in the success method of the .ajax call.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

any idea how (if even possible) to call java method with optional parameters from
Is it possible to call a web service from within Flash (using AS3)? Or
Is it possible to call Server.Execute with a .NET .aspx page from classic ASP?
Is it possible to call a class method of all objects in a list?
Is it possible to call an api exposed in COM exe server from NSIS
It's possible to call .NET from MATLAB, so I thought I would try to
Is it possible to call functions from class like this: $class = new class;
Is it possible to call a method that is an attribute? I mean, I
Is it possible to reflect on an explicit interface implementation from the call stack?
I'm using a third party component that I call a method passing a model

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.