I have a javascript array with values of checkbox selected. I want to pass this javascript array to asp array so that I can update the database.

I am using Jquery to get checkbox value

$('.checkboxes_to_delete:checked').each(function (key, value)
{           
    dataToBeDeleted.push($(this).val());
    alert(dataToBeDeleted);
});
link|improve this question

64% accept rate
feedback

4 Answers

up vote 2 down vote accepted

The easiest way is probably to use your Javascript to put the values into a hidden textbox on your page, and then your ASP code can pull that value down like any other form value.

link|improve this answer
feedback

Have you considered a checkboxlist control?

link|improve this answer
feedback

Send your array using $.post:

//Javascript

var myarray = [1, 2, 3, 4, 5];
$.post("Default.aspx", { data: myarray }, function (r) { /* callback */ }, "text");

In the code-behind (Default.aspx.cs) you can access your array by using Request["data[]"]. Your data will be a CSV.

//C#

string v = Request["data[]"];
//v == "1,2,3,4,5"; (true)
link|improve this answer
Oh.. It's an ajax approach. – Tocco Jul 8 '11 at 16:04
feedback

What I have done in the past is put the data from the JavaScript array into a hidden textbox with commas between the values. Then post-back and read the hidden textbox, and use string.Split() to seperate out into an array server-side.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.