Hum, I think if you want to send that array up to the server side and process it?
It not 100% clear the data type. But I would consider just adding a web method to the page in question.
So, you code say is this:
var userchoise = new Array();//this is my array
for (var i = 0; i < sayi; i++) {
if (chks[i].checked) {
userchoise.push(chks[i].id);
}
}
$.ajax({
type: "POST",
url: 'MyWebpageTest.aspx/PassArray',
data: JSON.stringify({ "MyIdList" : userchoise }),
contentType: "application/json; charset=utf-8",
datatype: "json",
success: function () {
alert('ok');
}
});
And the server side Sub in the web page?
This looks ok:
<WebMethod()>
Public Shared Sub Pass1(MyIdList As Integer())
For Each v As Integer In MyIdList
Debug.Print(v)
Next
' code here to write array of id's to database.
End Sub
The above assumes jQuery for the ajax post. Do keep in mind that you not have to set a page post back. Nor bother with a page post back. The effort to get a page post back (with hidden controls) is a bit of setup. And this means you don't need nor have a page post back anyway.
And in above, I put the sub in the same as the web page - but that web page class will NOT have a instance created - so I used "shared" (which is static in c#). So above would become this:
[WebMethod()]
public static void Pass1(int[] MyIdList)
{
foreach (int v in MyIdList)
Debug.Print(v);
}
So I think just passing the array up without a bunch of hidden fields, and even having to setup a post back? You can just send the array. A small Sub (void function) that just sends the array to the server means at that point you can do what you please/want with the array. You don't mention if the array is just a list of "id" or has some type of additional structure. I think a hidden field/text box is possible - but you have to execute a post back, and either way its more steps - the ajax calls are really simple, and the types are not only strong, but the json string parameters match what you declare server side - so I think you write the least amount of js code with this approach, and no additonal client side controls are required - except for jQuery.
fetchto send data from a web browser back to a asp.net page on the server. That page can store the data in the database. developer.mozilla.org/en-US/docs/Web/API/Fetch_API