473,387 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Drop down list selected value not submitting

Hi there

I am populating an empty <asp:dropdownlist on the client side using
Javascript using the following code

Heres my dropdown list
<asp:dropdownlist id="ddlDealers" Runat="server"></asp:dropdownlist>

heres the Java
var myDropDownList = frmMain.ddlDealers;

for (var cnt=0;cnt<=dealers.length-1;cnt = cnt + 2){
var opt = new Option(dealers[cnt],dealers[cnt],0,0);
myDropDownList.options[myDropDownList.options.length] = opt;
}
where dealers() is an array of values

the list is populated correctly and it all looks fine
my problem is that when I post the page using a <:asp Button the
selected value of the list is not being picked up on the server. Lets
say I selected 'Steve' in my drop down list, a simple test in my
Page_onload as follows returns NULL.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Response.Write myDropDownList.SelectedValue
End Sub

The only time I can get the selected value from a dropdown is when I
have populated the drop down at the server in the normal .NET fashion,
but this requires an extra trip to the server which I am trying to
avoid.

Any ideas??

Mark

Feb 15 '06 #1
4 9163
Have you tried using

Request.Form("myDropDownList")

I have had issues with postbacks and grabbing .SelectedValue from a DD.
Request.Form always seems to help in those weird situations.

Hope it helps,
Jeremy Reid
http://blackstaronline.net

Feb 15 '06 #2
Hey that works thanks.

I guess because the Drop down list items aren't created on the server
side the client side selected item does not match with the server side
data, or something like that. Meaning you have to revert to a more
classic ASP style Request.Form

Thanks
Mark

Feb 15 '06 #3
It's because with dynamically added options, such as that, are not
persisted in ViewState, so the DDL control doesn't actually know
anything about those members.

When you post back, it parses the view state to look for the value you
are looking for. Request.Form gets the post variables, rather than
matching the posted selected value to the value in view state.

Feb 15 '06 #4
thanks for the info

So if I want to dynamically populate drop down lists, is using
Request.Form the best method to use or is there a more elegant
solution. I am using Callback to retrieve the list data from the
server

var xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
etc..

can the viewstate be updated during this callback to the server?

Feb 16 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: deko | last post by:
I populate a drop-down list like this: echo "<select>"; foreach ( $ip_list as $var ) { echo "<option>"; echo $var; echo "</option>"; } echo "</select>";
46
by: Kingdom | last post by:
In my data base I have a list of componet types e.g. type A - I have 8 off - type B I have 12 off etc. I'm using Set objRS = objDC.Execute("Select DISTINCT Component_Type FROM Parts_Table") ...
2
by: Patrick | last post by:
Hello, I have a drop down list that when a value is selected the page refreshes itself but the selected value changes back to the default value. I would like to keep the selected value after the...
4
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by...
1
by: Dan | last post by:
This is one that has me stumped and I need an expert's input. Any ideas why the values from the second script-generated drop down list isn't recognized by the script to add time values to the...
2
by: Yoshitha | last post by:
hi I have 2 drop down lists in my application.1st list ontains itmes like java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the items like 50,60,70,80,90,100. i will...
5
by: Vigneshwar Pilli via DotNetMonster.com | last post by:
string connectionString1 = "server=(local); user=sa;password=sa; database=sonic"; System.Data.SqlClient.SqlConnection dbConnection1 = new System.Data.SqlClient.SqlConnection(connectionString1);...
3
by: John Walker | last post by:
Hi, On an ASP.NET page I have a drop down list control. When the user pulls down the list and makes a selection, I perform validation, and if the validation fails I want the selected item in...
2
by: giandeo | last post by:
Hello all, It's almost a couple of weeks since i am struggling to get this code work. Unfortunately, i am stuck. There seems to be no hope... Please Help....... I am working with an asp page...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.