Javascript to C#

D

DFDavis

I have a bunch of dynamically created checkboxes that I add to the a
label in the html through my C# code. Then I also have a javascript
function that goes through and identifies which checkboxes are checked
when the user clicks on the submit button. My question now is, how
would I go about getting the list of checked boxes back to my C#
program? I am not sure if you can pass an array from javascript to C#
or even exactly how you create an array in javascript. However, my
code for finding the checked boxes is like this :

function Select(x){
l=document.form1;
n=l.elements.length;
var i=0;
for(i=0;i<n;i++){
if(l.elements.type=='checkbox' &&
l.elements.checked){
// Add element value to the array
}
}
}

any help would be greatly appreciated.

Thanks,
Dan
 
M

Michael Nemtsev

Hello DFDavis,

Start from here http://groups.google.com/groups?q=dotnet+pass+javascript+array

as one solution is to create the string that represent your array (smth like
serialized array), put that string into hidden asp.net textbox and use form.submit()
to send data to server

D> I have a bunch of dynamically created checkboxes that I add to the a
D> label in the html through my C# code. Then I also have a javascript
D> function that goes through and identifies which checkboxes are
D> checked when the user clicks on the submit button. My question now
D> is, how would I go about getting the list of checked boxes back to my
D> C# program? I am not sure if you can pass an array from javascript to
D> C# or even exactly how you create an array in javascript. However,
D> my code for finding the checked boxes is like this :
D>
D> function Select(x){
D> l=document.form1;
D> n=l.elements.length;
D> var i=0;
D> for(i=0;i<n;i++){
D> if(l.elements.type=='checkbox' &&
D> l.elements.checked){
D> // Add element value to the array
D> }
D> }
D> }
D> any help would be greatly appreciated.
D>
D> Thanks,
D> Dan
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
G

Guest

If your checkboxes are inside a FORM field, then when the page is posted,
they will all be in the Request.Form collection.
Peter
 
D

DFDavis

Thank you both for your help, I finally got it working.

Dan

If your checkboxes are inside a FORM field, then when the page is posted,
they will all be in the Request.Form collection.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




DFDavis said:
I have a bunch of dynamically created checkboxes that I add to the a
label in the html through my C# code. Then I also have a javascript
function that goes through and identifies which checkboxes are checked
when the user clicks on the submit button. My question now is, how
would I go about getting the list of checked boxes back to my C#
program? I am not sure if you can pass an array from javascript to C#
or even exactly how you create an array in javascript. However, my
code for finding the checked boxes is like this :

function Select(x){
l=document.form1;
n=l.elements.length;
var i=0;
for(i=0;i<n;i++){
if(l.elements.type=='checkbox' &&
l.elements.checked){
// Add element value to the array
}
}
}

any help would be greatly appreciated.

Thanks,
Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top