Javascript to C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DFDavis

    #1

    Javascript to C#

    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.form 1;
    n=l.elements.le ngth;
    var i=0;
    for(i=0;i<n;i++ ){
    if(l.elements[i].type=='checkbo x' &&
    l.elements[i].checked){
    // Add element value to the array
    }
    }
    }

    any help would be greatly appreciated.

    Thanks,
    Dan

  • Michael Nemtsev

    #2
    Re: Javascript to C#

    Hello DFDavis,

    Start from here http://groups.google.com/groups?q=do...vascript+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

    DI have a bunch of dynamically created checkboxes that I add to the a
    Dlabel in the html through my C# code. Then I also have a javascript
    Dfunction that goes through and identifies which checkboxes are
    Dchecked when the user clicks on the submit button. My question now
    Dis, how would I go about getting the list of checked boxes back to my
    DC# program? I am not sure if you can pass an array from javascript to
    DC# or even exactly how you create an array in javascript. However,
    Dmy code for finding the checked boxes is like this :
    D>
    Dfunction Select(x){
    Dl=document.for m1;
    Dn=l.elements.l ength;
    Dvar i=0;
    Dfor(i=0;i<n;i+ +){
    Dif(l.elements[i].type=='checkbo x' &&
    Dl.elements[i].checked){
    D// Add element value to the array
    D}
    D}
    D}
    Dany help would be greatly appreciated.
    D>
    DThanks,
    DDan
    ---
    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


    Comment

    • Peter Bromberg [C# MVP]

      #3
      RE: Javascript to C#

      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:

      UnBlog:





      "DFDavis" wrote:
      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.form 1;
      n=l.elements.le ngth;
      var i=0;
      for(i=0;i<n;i++ ){
      if(l.elements[i].type=='checkbo x' &&
      l.elements[i].checked){
      // Add element value to the array
      }
      }
      }
      >
      any help would be greatly appreciated.
      >
      Thanks,
      Dan
      >
      >

      Comment

      • DFDavis

        #4
        Re: Javascript to C#

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

        Dan


        Peter wrote:
        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:

        UnBlog:

        >
        >
        >
        >
        "DFDavis" wrote:
        >
        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.form 1;
        n=l.elements.le ngth;
        var i=0;
        for(i=0;i<n;i++ ){
        if(l.elements[i].type=='checkbo x' &&
        l.elements[i].checked){
        // Add element value to the array
        }
        }
        }

        any help would be greatly appreciated.

        Thanks,
        Dan

        Comment

        Working...