<head runat="server"> <title></title> <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"> </script> <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script> <script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script> <script language="javascript" type="text/javascript"> $(function () { var jsonobj = []; var jsonStr = ""; $("#btngen").click(function () { $("#Content").empty(); var txt = "<input type='Text'/><br />"; var num = $("#txt_numnber").val(); $("#Content").append("<table>"); for (var i = 0; i < num; i++) { var tbl = "<tr><td>Cheque Number</td><td><input type='text' id='txtChq" + i + "'/></td><td>Amount</td><td><input type='text' id='txtAmount" + i + "'/></td><table><tbody><tr>"; $("#Content").append(tbl); } $("#Content").append("</tr></tbody></table></tr></table>"); }); /*#btnget*/ $("#btnget").click(function () { var i = 0; var urltohandle = 'ChecqueDetails.ashx'; var chk = $("#Content").children(); //// var jsonobj = []; //// var jsonStr = ""; //// var ConstStr = ","; var final; if ($(chk).length > 0) { for (var k = 0; k < ($(chk).length - 1) / 2; k++) { var ChkValue = $("#txtChq" + k).val(); var Chkamt = $("#txtAmount" + k).val(); // alert(ChkValue + " " + Chkamt); jsonobj.push({ "ChequeNumber": ChkValue, "Amount": Chkamt }); } jsonStr = JSON.stringify(jsonobj); jsonStr = jsonStr.replace('[', ''); jsonStr = jsonStr.replace(']', ''); //// alert(jsonStr); //// var _obj = jQuery.parseJSON(jsonStr); //// alert(_obj[0].ChequeNumber); //// jsonStr = JSON.stringify(_obj); //// alert(jsonStr); $("#<%= hidden_value.ClientID %>").text(jsonStr); $("#<%= lbl_json.ClientID %>").text(jsonStr); $.ajax({ url: urltohandle, // type:"POST", cache: true, async: true, dataType: "json", contentType: "application/json; charset=utf-8", data: jsonStr, success: function (data) { alert(data); }, error: function (data, status, jqXHR) { alert('There was an error.'); } }); //// console.log(jsonStr); //// var _obj = jQuery.parseJSON(jsonStr); //// $("#lit_txt").text(jsonStr); //// console.log(_obj[0].chk); } }); $("#<%=btnColor.ClientID %>").click(function () { }); }); </script> </head> <body> <form id="form1" runat="server" action="Default4.aspx" method="post"> <input type="button" id="btngen" value="Generate" /> <input type="text" id="txt_numnber" /> <div id="Content"> </div> <input type="hidden" runat="server" id="hidValue"/> <input type="button" runat="server" id="btnget" value="Get" /> <div id="txt_lit"> </div> <asp:Label runat = "server" ID="lbl_json" EnableViewState="true"> <asp:HiddenField runat="server" ID="hidden_value" /> <asp:Button runat="server" ID="btnColor" Text="Change" onclick="btnColor_Click" /> </form> </body> </html>
<%@ WebHandler Language="C#" Class="ChecqueDetails" %> using System; using System.Web; using System.Data; using System.Collections.Generic; using System.Web.Services; using System.Web.Script.Serialization; using System.Runtime.Serialization; [System.Web.Services.WebService(Namespace = "http://tempuri.org/")] public class ChecqueDetails : IHttpHandler { public void ProcessRequest (HttpContext context) { context.Response.ContentType = "application/json"; context.Response.ContentEncoding = System.Text.Encoding.UTF8; object obj=context.Request; // JavaScriptSerializer serializer = new JavaScriptSerializer(); // string str = serializer.Serialize(obj); // System.Web.Script.Serialization.JavaScriptSerializer jsp = (System.Web.Script.Serialization.JavaScriptSerializer)context; string ChequeNumber = context.Request["ChequeNumber"]; } public bool IsReusable { get { return false; } } }
<pre>
</pre>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)