locked
How to send hidden field value to code behind c# using JQ Grid RRS feed

  • Question

  • User-471420332 posted

    How to send hidden field value to code behind c# and I am not using asp.net button click and I am using html button. I want to send mails to selected checkbox checked user from JQ Grid.

    Below is my Script:

    <script type="text/javascript">
    
        jQuery(document).ready(function () {
            var grid = $("#dataGrid");
    
            grid.jqGrid({
                url: '<%=ResolveUrl("ViewCandidate.aspx/GetDataFromDB") %>',
                datatype: 'json',
                mtype: 'POST',
                serializeGridData: function (postData) {
                    return JSON.stringify(postData);
                },
    
                ajaxGridOptions: { contentType: "application/json" },
                loadonce: false,
                //toolbar: [true, "top"],
                colNames: ['CandidateId', 'Name', 'LoginId', 'MobileNo'],
                colModel: [
                           { name: 'CandidateId', index: 'CandidateId', width: 90, stype: 'text' },
                           { name: 'Name', index: 'Name', width: 100, stype: 'text', sortable: true, editable: true },
                           { name: 'LoginId', index: 'LoginId', width: 250, editable: true },
                           { name: 'MobileNo', index: 'MobileNo', width: 150, editable: true },
                ],
    
    
                viewrecords: true,
                gridview: true,
                multipleSearch: true,
                rowNum: 10,
                rowList: [10, 20, 300],
                multiselect: true,
                pager: "#pager",
                viewrecords: true,
                gridview: true,
                rownumbers: true,
                height: 230,
                jsonReader: {
                    root: function (obj) {
                        return typeof obj.d === "string" ? $.parseJSON(obj.d) : obj.d;
                    },
                    repeatitems: false
                },
                caption: 'Candidate details'
            }).navGrid('#pager', { search: true, edit: false, add: false, del: false, searchtext: "Search" });
    
            $("#selectAll").click(function () {
                grid.jqGrid('resetSelection');
                var ids = grid.jqGrid('getDataIDs');
                for (var i = 0, il = ids.length; i < il; i++) {
                    grid.jqGrid('setSelection', ids[i], true);
                }
            });
    
            $("#clear").click(function () {
                grid.jqGrid('resetSelection');
            });
            //$("#getSelected").click(function () {
            $("#getSelected").click('click', function () {
                var ids = grid.jqGrid('getGridParam', 'selarrrow');
                if (ids.length > 0) {
                    var names = [];
                    for (var i = 0, il = ids.length; i < il; i++) {
                        var Email = grid.jqGrid('getCell', ids[i], 'LoginId');
                        names.push(Email);
                        $("#ContentPlaceHolder1_Label1").text(names);
                  //      $("#myspan").text(names);
                      //  alert("Email are:" + names);
                    }
                 //   alert ("Names: " + names.join(", ") + "; ids: " + ids.join(", "));
                    $("#names").html(names.join(", "));
                    $("#dialog-confirm").dialog({
                        height: 280,
                        modal: true,
                        buttons: {
                            'Cancel': function () {
                                $(this).dialog('close');
                            },
                            'Confirm': function () {
                                alert("Confirm");
                                //alert ("Names: " + names.join(", ") + "; ids: " + ids.join(", "));
                                /*$.ajax({
                                    type: "POST",
                                    url:  "/cpsb/unprocessedOrders.do",
                                    data: { method: "releaseTowics",
                                        orderNum: JSON.stringify(ids),
                                        names: JSON.stringify(names)
                                    },
                                    dataType: "json"
                                    success: function(msg){
                                        alert(msg);
                                    },
                                    error: function(res, status, exeption) {
                                        alert(res);
                                    }
                                });*/
                            }
                        }
                    });
                }
            });
        });
    
    </script>

    If I will use the html button, then Java Script method is working, below is my code:

    <fieldset>
        <table id="dataGrid" style="text-align: center;"></table>
        <div id="pager"></div>
    
       <asp:HiddenField ID="Label1" runat="server"></asp:HiddenField>
    </fieldset>
    <fieldset>
       <input id="getSelected" type="button" value="Get Selected"> 
       <input id="selectAll" type="button" value="Select All">
       <input id="clear" type="button" value="Clear Selection">
    </fieldset>

    Below is my aspx.cs code:

     [WebMethod]
    public static List<Dictionary<string, object>> GetDataFromDB()
    {
    
      //  string myEmailid = Email;
        DataTable dt = new DataTable();
        using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["my_ConnectionString"].ToString()))
        {
            using (SqlCommand cmd = new SqlCommand("SELECT CandidateId, Name, LoginId, MobileNo from Table_Reg_CandidateInfo ORDER BY CandidateId", con))
            {
                con.Open();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dt);
                System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
                Dictionary<string, object> row;
                foreach (DataRow dr in dt.Rows)
                {
                    row = new Dictionary<string, object>();
                    foreach (DataColumn col in dt.Columns)
                    {
                        row.Add(col.ColumnName, dr[col]);
                    }
                    rows.Add(row);
                }
                return rows;
            }
    
        }
    
    }

    Friday, May 13, 2016 6:05 AM

Answers

  • User-271186128 posted

    Hi mazhar,

    How to send hidden field value to code behind c# and I am not using asp.net button click and I am using html button. I want to send mails to selected checkbox checked user from JQ Grid.

    You can create a webmethod (with parameter), and use JQuery to get the hidden field value and call the webmethod.

    Please refer to the following articles:

    http://www.aspsnippets.com/Articles/Calling-ASPNet-WebMethod-using-jQuery-AJAX.aspx

    Best regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 13, 2016 9:23 AM