?
Solved

ASP.NET / DropDownlist JavaScript Problem

Posted on 2005-03-21
10
Medium Priority
?
995 Views
Last Modified: 2008-03-10

I have an ASP.NET DropDownList server control which gets populated on the client side via JavaScript, like so:

var oOption = document.createElement('OPTION');
oOption.value = sText;
oOption.text = sText;
listbox.options.add(oOption);

When a postback occurs, this ListBox doesn't contain crap. It's empty.

I've tried checking it for contents in Page_Load() and in some of the handlers. Nowhere does it seem to arrive with the items I added through JavaScript.
0
Comment
Question by:prashanthan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 8

Expert Comment

by:razo
ID: 13590933
try calling the javascript function that populates the dropdownlist from the page_load event
0
 
LVL 26

Accepted Solution

by:
Rejojohny earned 1000 total points
ID: 13591034
listbox, dropdownlist etc does not maintain the items added on the clients-side when a postback occurs as the viewstate does not know of these items added from the client (on the browser)
0
 
LVL 7

Expert Comment

by:brdrok
ID: 13591170
hmmm....dunno if that is possible via javascript but maybe add the newly added items into the url string (cookies maybe) and then extract that new data inside the page_load or whevever?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:Thalox
ID: 13591210

yes Rejojohny is right.
But you can access the value the user selected in the dropdownlist.

on client add option with javascript
var oOption = document.createElement('OPTION');
oOption.value = "TestVal";
oOption.text = "TestVal";
listbox.options.add(oOption);

and on server you can use
Request.Form["listbox"]
this will return the selected value ("TestVal" in this case)

hope that helps
Thalox
0
 
LVL 2

Author Comment

by:prashanthan
ID: 13599335
I tried to retrive the value through Request.Form("listbox"), but it always return the first item of the dropdownlist.

Is there any other way to acheive it.

0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 13599657
Request.Form("listbox") will always give you the selected value in the listbox and not the whole list of items ..
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 13852684
Please do have alook at my comments ..
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question