Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / June 2007

Tip: Looking for answers? Try searching our database.

Options added to select list with JavaScript lost on postback

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mario Vargas - 21 Jun 2007 21:52 GMT
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
Steve C. Orr [MCSD, MVP, CSM, ASP Insider] - 21 Jun 2007 22:27 GMT
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.

Signature

I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net

> Hello all,
>
[quoted text clipped - 21 lines]
>
> Mario
Mario Vargas - 21 Jun 2007 22:46 GMT
Thanks, Steve! I also thought about this approach, but was hoping for a
better way...

Mario

> 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.
[quoted text clipped - 25 lines]
>>
>> Mario
Laurent Bugnion, MVP - 22 Jun 2007 08:20 GMT
Hi,

> 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
Signature

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

Mario Vargas - 22 Jun 2007 14:21 GMT
Hi Laurent,

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

Mario

> Hi,
>
[quoted text clipped - 11 lines]
> Greetings,
> Laurent

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.