locked
Sending values generated by Modal Dialog box to Database - How To RRS feed

  • Question

  • User2015884762 posted

    Hi,I have got some data populated into a grid view.I, then have a modal dialog box with a few input boxes that pops up when a user clicks on the cell in the grid view. I know I can loop through the gridview and push each cell value into the db, but what about the values in the modal dialog's input boxes. How do I push them into the database. Should I create hidden fields for each cell that contains the input boxes value ? Looking forward for some suggestion on how to implement this. I should be able to code it myself, so suggestion woul be more than enough for now.

    Friday, March 1, 2019 2:52 AM

Answers

  • User61956409 posted

    Hi callykalpana,

    callykalpana

    what about the values in the modal dialog's input boxes. How do I push them into the database.

    You can try to use jQuery AJAX to make request to a web method or backend service for submitting the user inputs in modal dialog and saving the values into database.

    Here is [a article with example](https://www.aspsnippets.com/Articles/jQuery-AJAX-call-with-parameters-example-Send-parameters-to-WebMethod-in-jQuery-AJAX-POST-call.aspx ) that explained how to send parameters to WebMethod in jQuery AJAX POST call.

    Example code:

    <script type="text/javascript">
    $(function () {
        $("[id*=btnSubmit]").click(function () {
            var obj = {};
            obj.name = $.trim($("[id*=txtName]").val());
            obj.age = $.trim($("[id*=txtAge]").val());
            $.ajax({
                type: "POST",
                url: "CS.aspx/SendParameters",
                data: JSON.stringify(obj),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (r) {
                    alert(r.d);
                }
            });
            return false;
        });
    });
    </script>

    You can also check [jQuery.ajax() documentation](http://api.jquery.com/jquery.ajax/) for details. 

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 1, 2019 5:17 AM

All replies

  • User-1716253493 posted

    replace input controls with server controls like textbox, checkbox etc

    Friday, March 1, 2019 4:04 AM
  • User61956409 posted

    Hi callykalpana,

    callykalpana

    what about the values in the modal dialog's input boxes. How do I push them into the database.

    You can try to use jQuery AJAX to make request to a web method or backend service for submitting the user inputs in modal dialog and saving the values into database.

    Here is [a article with example](https://www.aspsnippets.com/Articles/jQuery-AJAX-call-with-parameters-example-Send-parameters-to-WebMethod-in-jQuery-AJAX-POST-call.aspx ) that explained how to send parameters to WebMethod in jQuery AJAX POST call.

    Example code:

    <script type="text/javascript">
    $(function () {
        $("[id*=btnSubmit]").click(function () {
            var obj = {};
            obj.name = $.trim($("[id*=txtName]").val());
            obj.age = $.trim($("[id*=txtAge]").val());
            $.ajax({
                type: "POST",
                url: "CS.aspx/SendParameters",
                data: JSON.stringify(obj),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (r) {
                    alert(r.d);
                }
            });
            return false;
        });
    });
    </script>

    You can also check [jQuery.ajax() documentation](http://api.jquery.com/jquery.ajax/) for details. 

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 1, 2019 5:17 AM