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

  • Home
  • SEARCH
  • 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 3606632
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:16:26+00:00 2026-05-18T21:16:26+00:00

I am trying to call a simple method in my code behind using Jquery

  • 0

I am trying to call a simple method in my code behind using Jquery with Ajax. But I get a 404 not found exception everytime. Unfortunately this is a web forms solution. So I dont have all the perks of MVC 🙁

It does get into the javascript method and gives the alert but won’t go into my c# method. My previous experience of using this Jquery method is in an MVC website. Is it compatible with webforms sites?

My Javascript is:

$(document).ready(function() {

              $('#btn_<%=UserStuff.tag %>').click(function() {                    

                  var value = $('#<%#Eval("tag") %>twink').val();
                  something(value);                    
              });
          });


          function something(theval) {

            alert(theval);

              $.ajax({
                  type: "POST",
                  url: "/Default.aspx/MyMethod?something=" + theval,
                  data: "{}",
                  contentType: "application/json; charset=utf-8",
                  dataType: "json",
                  success: function(msg) {
                      alert(msg);
                  }
              });
          }
}

And my C# code is:

   public JsonResult MyMethod(string something)
{
    JsonResult ret = new JsonResult();      

    return ret;
}

Thanks in advance.

  • 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-05-18T21:16:27+00:00Added an answer on May 18, 2026 at 9:16 pm

    Your method returns JsonResult. This is MVC specific and you cannot use it in a webforms application.

    If you want to call methods in the code behind in a classic WebForms application you could use PageMethods:

    [WebMethod]
    public static string GetDate()
    {
        return DateTime.Now.ToString();
    }
    

    And then to call the method:

    $.ajax({
        type: 'POST',
        url: 'PageName.aspx/GetDate',
        data: '{ }',
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        success: function(msg) {
            // Do something interesting here.
        }
    });
    

    And here’s a full working example I wrote for you:

    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Web.Services" %>
    <script type="text/C#" runat="server">
        [WebMethod]
        public static string SayHello(string name)
        {
            return "Hello " + name;
        }
    </script>
    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
        <script type="text/javascript" src="/scripts/jquery-1.4.1.js"></script>
        <script type="text/javascript">
            $(function () {
                $.ajax({
                    type: 'POST',
                    url: 'default.aspx/sayhello',
                    data: JSON.stringify({ name: 'John' }),
                    contentType: 'application/json; charset=utf-8',
                    dataType: 'json',
                    success: function (msg) {
                        // Notice that msg.d is used to retrieve the result object
                        alert(msg.d);
                    }
                });
            });
        </script>
    </head>
    <body>
        <form id="Form1" runat="server">
    
        </form>
    </body>
    </html>
    

    PageMethods are not limited to simple argument types. You could use any type as input and output, it will be automatically JSON serialized.

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

Sidebar

Related Questions

I am trying to call a webservice using ssl. How do i get the
I'm trying to call the SQL statement below but get the following error: System.Data.SqlClient.SqlException:
I have a simple WCF service that I call server side from code behind
When trying to call Close or Dispose on an SqlDataReader i get a timeout
I'm trying to call a php webservice using WCF. I googled some public php
I'm trying to call the OpenThemeData (see msdn OpenThemeData ) function but I couldn't
I am trying to call out to a legacy dll compiled from FORTRAN code.
I'm very new to jQuery and trying to run a pretty simple jQueryUI dialog
Was trying out some code with the EF code first method and ran into
I'm trying to call an Antlr task in my Ant build.xml as follows: <path

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.