ASP .NET and Javascript

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

    ASP .NET and Javascript

    Hi,

    I have an ASP .NET page with codebehind in a vb file.
    The page has a dropdown control, and a JS function which used HTTP XML
    Request to get the data from the database, and populate the dropdown.
    Actually, the JS creates the OPTION elements using th retrieved db
    data, and adds them to the SELECT element using DOM objects.

    The dropdown works ok, and the items are visible, but when the user
    clicks "Save" button, and the page posts back to the server, in the VB
    codebehind, the selected value in the dropdown is empty, and the items
    collection is empty.

    Why is this? How can I fix this behavior?

    Thanks in advance,

    Richard
  • tomtom.wozniak@gmail.com

    #2
    Re: ASP .NET and Javascript

    On Apr 15, 5:38 pm, Rick <e_man_onl...@h otmail.comwrote :
    Hi,
    >
    I have an ASP .NET page with codebehind in a vb file.
    The page has a dropdown control, and a JS function which used HTTP XML
    Request to get the data from the database, and populate the dropdown.
    Actually, the JS creates the OPTION elements using th retrieved db
    data, and adds them to the SELECT element using DOM objects.
    >
    The dropdown works ok, and the items are visible, but when the user
    clicks "Save" button, and the page posts back to the server, in the VB
    codebehind, the selected value in the dropdown is empty, and the items
    collection is empty.
    >
    Why is this? How can I fix this behavior?
    >
    Thanks in advance,
    >
    Richard
    Hard to tell w/o any actual javascript samples to go by. :)

    I'll take a shot at it though.

    <html>
    <head>
    <script>
    function set_option_item (sendValue,disp layValue) {
    var elem = document.create Element('option ');
    elem.setAttribu te('value',send Value);
    elem.innerHTML = displayValue;
    return elem;
    }
    function load_option_ele ments () {
    var sel = document.getEle mentById('dropd own');
    for (i=1; i<10; ++i)
    sel.appendChild (set_option_ite m('00'+i,'Item #'+i));
    }
    </script>
    </head>
    <body onload="load_op tion_elements() ;">
    <form method=post action="http://10.50.10.109/cgi-bin/envpost.cgi">
    <select name="dropdown" id="dropdown">
    </select>
    <input type="submit" value="Save" />
    </form>
    </body>
    </html>

    This displays 9 items labeled "Item #1" to "Item #9" within the drop-
    down select box. A three-digit numeric is successfully posted to the
    server using the above code.

    Can't help ya with server-side VB here (this is a javascript thread).

    Post some code that you're using to test (make is as simple as
    possible) to get some others willing to assist.

    -Tom Woz

    Comment

    Working...