Take the 2-minute tour ×

What I have is a table that holds 3 input elements, They represent order, name, value. The user can add a new row of 3 inputs to add as many of these sets of data as they want.

To accomplish the dynamically adding in of inputs I use jquery's clone method.

That works fine and I am able to iterate through each and grab the values, however the real pain I am having is that when the user has entered in all of the data I want to pass that data to an asp.net page through jQuery's post method. How do I go about passing an array of strings so that I send this format to the asp.net page, and when I've done that how do i parse the data on the asp.net side of it.

Desired Data Format:

["Name|Link|Order", "Name|Link|Order", "Name|Link|Order"]

jquery Code so far:

$("#saveBtn").click(function (e) {



        //Perform Save Operation
        var saveString = "";

        $("#addTable tbody>tr").each(function () {

            var o = $(this).find(".hsaorder").val();
            var n = $(this).find(".hsaname").val();
            var l = $(this).find(".hsalink").val();

            saveString += n + "|" + l + "|" + o ;


        ////// Create Array here or some other method?

        $.post("/modules/H/Modify.aspx", { OBVIOUSLY SOMETHING GOES HERE});

        // Remove all but top table element to return to original state
        $("#addTable tbody>tr").not("#addTable tbody>tr:first").remove();

share|improve this question
Have you considered, and rejected, JSON? –  arootbeer Nov 23 '10 at 19:38
NOt at all, just not familiar with using it in jquery ajax and more importantly interacting with it in C#(.Net) –  Seth Duncan Nov 23 '10 at 19:44
add comment

4 Answers

up vote 1 down vote accepted

Seth, these concatenation like "|" + something + "|" is really not a good practice. Try to avoid it, and you'll save a lot of time in further, I promise.

See how I'm doing this:

First, on client side put everything to a true JSON-string, like this:

    var saveAr = [];



        saveAr.push({ order: o, name: n, link: l });

    $.post("/modules/H/Modify.aspx", { changes: JSON.stringify(saveAr)});

Then you need to somehow parse it on the server side. Best to do this is to install JSON.Net dll (just google it), and then parse it:

var rows = JArray.Parse(Request["changes"]);
foreach (var row in rows) {
   var order = row.Value<string>["order"];
   var name = row.Value<string>["name"];
   var link = row.Value<string>["link"];

   // do something with it

You may have problems with JSON.stringify in old versions of IE, but it can be fixed by applying this patch: https://github.com/douglascrockford/JSON-js

Warning: I not compiled the code above, so don't 100% trust to this, just take an idea.

share|improve this answer
Would love to use this but I don't seem to see a JArray object int he json.net library i have added –  Seth Duncan Nov 23 '10 at 20:45
Took some work figuring out how to use JArray and how to covert to values. But this is definitely what I was looking for. –  Seth Duncan Nov 23 '10 at 21:27
add comment
    var saveArray = [];


        saveArray.push("|" + l + "|" + o);


    var yourPost = {'save': saveArray.join(',')};
    $.post("/modules/H/Modify.aspx", yourPost, function(data){
       //your server response is in data;

To retrieve your data on the other side, split the post by first commas then your pipe delimiter. (Of course if you expect commas in your data, choose a different delimiter in the join.)

I don't use aspx often but here's how I'd probably go about retrieving and splitting the data that was posted. (vb) To retrieve the "Columns" within the rows, just do the same thing except now with your pipe delimiter.

//how to retrieve and then split the rows out
Dim strData As String = Request.Post("save")
Dim separator() As Char = New Char() {","}
Dim rows() As String = strData.Split(separator)

For Each str As String In rows
share|improve this answer
add comment

If you really need to roll your own format instead of just serializing the form, you can try something like this (replacing your code starting at //Perform Save Operation):

var saveArray = $('#foo tr').map(function(i, e) {
  var result = [];
  return [result.join('|')];

...and then:

$.post("/modules/H/Modify.aspx", { data: saveArray } );

Then just unravel and process the data in Modify.aspx.

share|improve this answer
Definitely a nice alternative to each. –  Seth Duncan Nov 23 '10 at 20:07
add comment

a very handful way which minimizes your coding is to serialize the data using json and deserialize it i asp.net page. you'll have the data already parsed for you.

share|improve this answer
add comment

Your Answer


