0

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);
});
MD Sayem Ahmed
29.3k27 gold badges115 silver badges183 bronze badges
asked Jul 8, 2011 at 15:32

4 Answers 4

2

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.

answered Jul 8, 2011 at 15:47
Sign up to request clarification or add additional context in comments.

Comments

2

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)
answered Jul 8, 2011 at 15:57

Comments

2

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.

answered Jul 8, 2011 at 16:26

Comments

0

Have you considered a checkboxlist control?

answered Jul 8, 2011 at 15:48

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.