473,480 Members | 4,985 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Options added to select list with JavaScript lost on postback

Hello all,

I am trying to dynamically add elements to a select list (which is running
on the server, runat="server") with JavaScript, but when I postback, the new
elements are lost. I'm not sure how to tell ASP.Net to post back these new
elements as well. Any ideas or sources where you could point me to will be
greatly appreciated. I am still using ASP.Net 1.1.

This is part of the code I am using to dynamically add the element:

myOpenerListCtrl.options[myOpenerListCtrl.options.length] = new Option(
districtName, districtID );

I also tried using standard DOM syntax:

var newOption = document.createElement( "option" );
newOption.setAttribute( "value", districtID );
newOption.innerText = districtName;
myOpenerListCtrl.appendChild( newOption )

But neither is kept in the postback.

Thanks!

Mario
Jun 21 '07 #1
4 2995
Most people add such data to a hidden form field, which you would then
manually process upon postback to keep the lists in sync on both ends.

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net
"Mario Vargas" <ma*********@thecourier.comwrote in message
news:eR*************@TK2MSFTNGP02.phx.gbl...
Hello all,

I am trying to dynamically add elements to a select list (which is running
on the server, runat="server") with JavaScript, but when I postback, the
new elements are lost. I'm not sure how to tell ASP.Net to post back these
new elements as well. Any ideas or sources where you could point me to
will be greatly appreciated. I am still using ASP.Net 1.1.

This is part of the code I am using to dynamically add the element:

myOpenerListCtrl.options[myOpenerListCtrl.options.length] = new Option(
districtName, districtID );

I also tried using standard DOM syntax:

var newOption = document.createElement( "option" );
newOption.setAttribute( "value", districtID );
newOption.innerText = districtName;
myOpenerListCtrl.appendChild( newOption )

But neither is kept in the postback.

Thanks!

Mario
Jun 21 '07 #2
Thanks, Steve! I also thought about this approach, but was hoping for a
better way...

Mario

"Steve C. Orr [MCSD, MVP, CSM, ASP Insider]" <St***@Orr.netwrote in
message news:5D**********************************@microsof t.com...
Most people add such data to a hidden form field, which you would then
manually process upon postback to keep the lists in sync on both ends.

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net
"Mario Vargas" <ma*********@thecourier.comwrote in message
news:eR*************@TK2MSFTNGP02.phx.gbl...
>Hello all,

I am trying to dynamically add elements to a select list (which is
running on the server, runat="server") with JavaScript, but when I
postback, the new elements are lost. I'm not sure how to tell ASP.Net to
post back these new elements as well. Any ideas or sources where you
could point me to will be greatly appreciated. I am still using ASP.Net
1.1.

This is part of the code I am using to dynamically add the element:

myOpenerListCtrl.options[myOpenerListCtrl.options.length] = new Option(
districtName, districtID );

I also tried using standard DOM syntax:

var newOption = document.createElement( "option" );
newOption.setAttribute( "value", districtID );
newOption.innerText = districtName;
myOpenerListCtrl.appendChild( newOption )

But neither is kept in the postback.

Thanks!

Mario

Jun 21 '07 #3
Hi,

Mario Vargas wrote:
Thanks, Steve! I also thought about this approach, but was hoping for a
better way...

Mario
To be fair, it's not ASP.NET which is guilty here, but the fact that the
items of a SELECT element are not transmitted on postback, but only the
selected value. Which makes sense, if you think of it, or else the
requests could be huge (think of these SELECT with the list of all
countries, for example).

Greetings,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft.ch
PhotoAlbum: http://www.galasoft.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Jun 22 '07 #4
Hi Laurent,

That's a very good point and something I didn't know about. Thanks for
sharing!

Mario

"Laurent Bugnion, MVP" <ga*********@bluewin.chwrote in message
news:uu**************@TK2MSFTNGP05.phx.gbl...
Hi,

Mario Vargas wrote:
>Thanks, Steve! I also thought about this approach, but was hoping for a
better way...

Mario

To be fair, it's not ASP.NET which is guilty here, but the fact that the
items of a SELECT element are not transmitted on postback, but only the
selected value. Which makes sense, if you think of it, or else the
requests could be huge (think of these SELECT with the list of all
countries, for example).

Greetings,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft.ch
PhotoAlbum: http://www.galasoft.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch

Jun 22 '07 #5

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

Similar topics

8
7880
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
12
6501
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
2
5190
by: BrianP | last post by:
Hi, I have had to invent a work-around to get past what looks like a JavaScript bug, the malfunctioning Perl-like JavaScript array functions including SPLICE() and UNSHIFT(). I have boiled it...
12
1897
by: Mark Fox | last post by:
Hello, I am attempting to do something very simple. I have a page MainPage.aspx and a popup window Popup.aspx. When users click on the linkbutton in the popup window I am looking to do some...
2
2427
by: kiranmn75 | last post by:
I want to dynamically populate a combo box through javascript. Data is coming from a array. Sometimes data list may contain items in excess of 2000. Explorer takes more than 5 seconds to...
3
6406
by: Beholder | last post by:
I hope that someone can help me with the following: Short background explenation: I have a shrfepoint page (newform.aspx) in a item list. On this page is a lookup column that displays a lookup...
7
16846
chunk1978
by: chunk1978 | last post by:
hello. so i have 2 select menus which add and remove options from a 3rd select menu... it seems, however, that it's not possible to use different select menus to toggle a 3rd, because when an...
1
5035
by: madflytom | last post by:
Hello, I'm trying to move the options of one select list to another select list. The "source" select list is divided into optgroups, and the "target" select list is not. I want to somehow keep...
7
1765
by: yanni | last post by:
I have some thing like this: <body> <form id="form1" runat="server"> <div> <asp:DropDownList ID="uxTestDropDownList" runat="server" /> <asp:Button ID="uxSubmitButton" runat="server"...
0
7040
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
6905
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
7041
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
7080
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...
1
6736
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5331
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4772
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1299
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
561
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.