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 6717023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:48:12+00:00 2026-05-26T08:48:12+00:00

How to receive posted values to variable in .asmx that was posted from extjs,

  • 0

How to receive posted values to variable in .asmx that was posted from extjs, so it can be saved using ado.net to database?

SENDING DATA WITH EXT.AJAX

{
    text: 'Add',
    formBind: true,
    disabled: true,
    handler: function () {

        var form = this.up('form').getForm();
        var formValues = form.getValues();

        var firstName = formValues.firstName;
        var lastName = formValues.lastName;

        if (form.isValid()) {

            Ext.Ajax.request({

                url: 'WebServices/WebService.asmx/AddAgent',
                headers: { 'Content-Type': 'application/json' },
                method: 'POST',
                jsonData: { FirstName: firstName, LastName: lastName }


            });
        }
    }
}

When submited, firebug reports error:
enter image description here

How to properly recieve this values in .asmx so they can be used in [WebMethod] and saved with Ado.Net?

    [Serializable]
    public class Agents
    {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }


    //CREATE
    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]

    public string AddAgent()
    {
        string connStr = ConfigurationManager.ConnectionStrings["AgentsServices"].ConnectionString; 

        using (SqlConnection connection = new SqlConnection(connStr))
        {
            connection.Open();

            using (SqlCommand command = new SqlCommand("insert into Agent(id, firstName, lastName) values(@id, @firstName, @lastName)", connection))
            {
                command.Parameters.AddWithValue("@firstName", FirstName); //here i get message( The name "FirstNAme does not exist in current context")
                command.Parameters.AddWithValue("@lastName", LastName); // -||-

                command.ExecuteNonQuery();

            }
        }       
    } 

EDIT:

No. stil 500 Internal Server Error:

enter image description here

  • 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-26T08:48:13+00:00Added an answer on May 26, 2026 at 8:48 am

    Your web method doesn’t seem to take any argument. Also your method expects to return a string and yet you do not return anything. So either return something or modify your method signature to void. Also you have set UseHttpGet = true and yet you are sending a POST request. Try like this:

    [WebMethod]
    [ScriptMethod]
    public void AddAgent(Agents agents)
    {
        string connStr = ConfigurationManager.ConnectionStrings["AgentsServices"].ConnectionString; 
        using (SqlConnection connection = new SqlConnection(connStr))
        {
            connection.Open();
            using (SqlCommand command = new SqlCommand("insert into Agent(id, firstName, lastName) values(@id, @firstName, @lastName)", connection))
            {
                command.Parameters.AddWithValue("@firstName", agents.FirstName);
                command.Parameters.AddWithValue("@lastName", agents.LastName);
                command.ExecuteNonQuery();
            }
        }       
    }
    

    Also since you have defined the Id property of your Agents model as a non-nullable integer I would recommend you sending a value for it:

    jsonData: { agents: { Id: 0, FirstName: firstName, LastName: lastName } }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Json.NET to deserialize a jQuery.post() JSON param. The raw value that's posted
I receive a string from a database query, then I remove all HTML tags,
I receive TypeError: Can't convert 'float' object to str implicitly while using Gambler.pot +=
In ASP.net MVC: How should/Can I pass Form data (From the View) to the
I asked a question regarding Bi linear transformations and received this answer: From that
I'm using Rails 2.3.8 and have a jQuery AJAX form using posted using: jQuery.fn.submitWithAjax
I've created a 3 screen wizard using the Zend_Form_SubForm example from the online reference
I have an ASP.NET MVC application that uses jQuery 1.3.2. On several of the
I want this class to initialize to receive a message to be saved and
Background I am developing an ASP.Net server side control that needs to talk to

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.