Send value to webform code behind using ajax RRS feed

  • Question

  • User444756084 posted

    I have a webform and am attempting to send a value to a function in my code behind on insert. It is not working. I am getting error: No overload for 'ListView3_ItemInserting' matches delegate 'EventHandler<ListViewInsertEventArgs>'. How can I get the value to the code behind?

    Jquery code:

    $('#ContentPlaceHolder1_Wizard1_ListView3_InsertButton').click(function () {
                    var sum = 0;
                    var sumIt = $('.getHrsVal').text();
                    $(sumIt).each(function () {
                        sum += +$(this).val();
                        url: "Default.aspx/ListView3_ItemInserting",
                        type: "POST",
                        data: "{'sumIT':'" + sumIt +"'}",
                        dataType: "json",
                        contentType: "application/json; charset=utf-8",
                       // data: JSON.stringify(sumIt),
                        success: function (data) {
                            //success data if any 
                        error: function (msg) { //handle error here 

    Code behind:

        protected void ListView3_ItemInserting(object sender, ListViewInsertEventArgs e, string sumIt)
            NEED VALUE HERE

    Sunday, September 1, 2019 9:28 PM

All replies

  • User-719153870 posted

    Hi gordon1221,

    As far as i kown, if you want to use ajax to send a parameter to the back code and get some data from that, you won't need to use a method with EvenArgs.

    A simple demo using ajax and a static method might help you understand what does that mean:


    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <script src="Scripts/jquery-3.3.1.min.js"></script>
            $(function () {
                $('#btninsert').click(function () {
                    var sumIt = "6";
                        type: "POST",
                        url: "AjaxInsertDemo.aspx/ItemInserting",
                        data: "{'sumIT':'" + sumIt + "'}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (data) {
                        error: function (msg) {
        <form id="form1" runat="server">
                <input type="button" id="btninsert" value="insert" />


            public static void ItemInserting(string sumIT)
                SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=DatabaseTestPool;Integrated Security=True");
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = con;
                    cmd.CommandText = "Insert into Options values('" + sumIT + "','D1')";
                catch (Exception ex)
                    throw (ex);

    For more information about using ajax and webmethod, please refer to this artical.

    Best Regard,

    Yang Shen

    Monday, September 2, 2019 5:09 AM