Click here to Skip to main content
14,825,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have created one web service with two methods. First method is without parameter calling on load which is working fine, my second method have dateparameter(textbox), i am not getting parameter value in code behind (on buttong click i am calling this parametrised function)


JavaScript
<script type="text/javascript">
        $j = $.noConflict();
        $j(document).ready(function () {
            $j.ajax({
                type: "POST",
                dataType: "json",
                url: "ClaimService.asmx/GetClaims",
                success: function (data) {
                    var datatableVariable = $j('#example2').DataTable({
                        data: data,
                        "bLengthChange": false,
                        "bFilter": false,
                        "bPaginate": true,
                        "pageLength": 10,
                        columns: [
                         { 'data': 'Name' },
                         { 'data': 'IntimationDate' },
                         { 'data': 'PolicyNo' },
                         { 'data': 'Status' },
                         ]
                    });
                }
            });

        });

        function GetDataByFilter() {
            var startDate = $j("[id*=startDate]").val();
            $j.ajax({
                type: "POST",
                dataType: "json",
                url: "ClaimService.asmx/GetClaimsByFilter",
                //data: '{"startDate": ' + startDate + '}',
                data: "{startDate: '" + startDate + "'}",
                success: function (data) {
                    var datatableVariable = $j('#example2').DataTable({
                        data: data,
                        "bLengthChange": false,
                        "bFilter": false,
                        "bPaginate": true,
                        "pageLength": 10,
                        columns: [
                         { 'data': 'Name' },
                         { 'data': 'IntimationDate' },
                         { 'data': 'PolicyNo' },
                         { 'data': 'Status' },
                         ]
                    });
                }
            });
        }    
    </script>



C#
[WebMethod]
        public void GetClaims()
        {
            var cs = ConfigurationManager.ConnectionStrings["SQLConnection"].ConnectionString;
            var students = new List<MemberDetails>();
            using (var con = new SqlConnection(cs))
            {
                var cmd = new SqlCommand("select * from Claim_Master", con) { CommandType = CommandType.Text };
                con.Open();
                var dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    var student = new MemberDetails
                    {
                        Name = dr["FirstName"].ToString(),
                        IntimationDate = dr["IntimationDate"].ToString(),
                        PolicyNo = dr["PolicyNo"].ToString(),
                        Status = dr["Status"].ToString()
                        //DocumentsReceived = dr["Document Recived"].ToString(),
                        //DocumentsPending = dr["Document Pending"].ToString()
                    };
                    students.Add(student);
                }
            }
            var js = new JavaScriptSerializer();
            Context.Response.Write(js.Serialize(students));
        }

        [WebMethod]
        public void GetClaimsByFilter(string startDate)
        {
            var cs = ConfigurationManager.ConnectionStrings["SQLConnection"].ConnectionString;
            var students = new List<MemberDetails>();
            using (var con = new SqlConnection(cs))
            {
                var cmd = new SqlCommand("select * from Claim_Master", con) { CommandType = CommandType.Text };
                con.Open();
                var dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    var student = new MemberDetails
                    {
                        Name = dr["FirstName"].ToString(),
                        IntimationDate = dr["IntimationDate"].ToString(),
                        PolicyNo = dr["PolicyNo"].ToString(),
                        Status = dr["Status"].ToString()
                        //DocumentsReceived = dr["Document Recived"].ToString(),
                        //DocumentsPending = dr["Document Pending"].ToString()
                    };
                    students.Add(student);
                }
            }
            var js = new JavaScriptSerializer();
            Context.Response.Write(js.Serialize(students));
        }



thanks in advance.

What I have tried:

I checked in browser i can see date value but i am not getting value in code behind, it is not coming into that second method (GetClaimsByFilter)
Posted
Updated 23-Jan-17 22:09pm
v3
Comments
F-ES Sitecore 24-Jan-17 4:01am
   
Try

data: {startDate: startDate},
Ravi Sargam 24-Jan-17 4:14am
   
Thank you so much...... ES Sitecore

1 solution

Try this,
data: JSON.stringify({ startDate: startDate})

This works! :)
   
Comments
Ravi Sargam 24-Jan-17 5:02am
   
Thank you.............

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900