Drop Down List Control , Select Value, and Javascript

G

Guest

Hi,

I've been asked to create a page that dynamically populates the contents of
related drop down lists using JavaScript, and then obviously posts things
back to the server.

For completeness, I re-produce example JavaScript below (this seemingly
works fine - but just to let you see what is going on)

e.g. var categoriesArray = TrendCategoriesHolder[intTrendIndex];
for ( i = 0; i <= categoriesArray.length - 1; i++)
{ var categoriesObject = categoriesArray;
var categoriesText = categoriesObject[0];
var categoriesValue = categoriesObject[2];
ddlTrendCategory.options = new Option(categoriesText,
categoriesValue);
}
var ddlTrendType = document.getElementById("ddlTrendType");
ddlTrendCategory.options[ddlTrendCategory.options.length] = new
Option("All Categories", 0);


When I post this back to the server, if i use
ddlTrendCategory.SelectedValue.ToString() it claims it evalutates to "". If i
use ddlTrendCategory.SelectedItem.Value.ToString() then it errors, with a
null reference error.

So, seemingly ASP.NET is not recognising that the drop down list has
contents. Is there a way round this, or is the whole approach I was asked to
do invalid and doomed to fail!

Help appreciated. Thanks in avance.
 
J

Jéjé

you have to retrieve the value by yourself.
like:
request.form("mydropdown")
will contain the selected value of the dropdown.

if your dropdownlist is not populated from the server side, you can't use
the server side object model. from a server side point of view, the
dropdownlist is empty, so you can't select anything from this point of view.


"craig@amtdatatechnologies"
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top