ASP .NET and Javascript

R

Rick

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
 
T

tomtom.wozniak

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,displayValue) {
var elem = document.createElement('option');
elem.setAttribute('value',sendValue);
elem.innerHTML = displayValue;
return elem;
}
function load_option_elements () {
var sel = document.getElementById('dropdown');
for (i=1; i<10; ++i)
sel.appendChild(set_option_item('00'+i,'Item #'+i));
}
</script>
</head>
<body onload="load_option_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
 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,141
Latest member
BlissKeto
Top