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);
});

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.

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)

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.

Comments

0

Have you considered a checkboxlist control?

Comments

Your Answer

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.