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 4 2940
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
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
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
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 This discussion thread is closed Replies have been disabled for this discussion. Similar topics
8 posts
views
Thread by Ashish Shridharan |
last post: by
|
12 posts
views
Thread by Kevin Lyons |
last post: by
|
2 posts
views
Thread by BrianP |
last post: by
|
12 posts
views
Thread by Mark Fox |
last post: by
|
2 posts
views
Thread by kiranmn75 |
last post: by
|
3 posts
views
Thread by Beholder |
last post: by
| | |
7 posts
views
Thread by yanni |
last post: by
| | | | | | | | | | |