April 2nd, 2008Asp.net and dropdown lists
I am slowing gaining some good experience in coding with visual studio 2008 and VB.NET and some C# for ASP.NET
But I fell into a corker this week
I have a simple form with a dropdown list box, the items in this drop down list box are populated from a data string obtained from an external webservice during the page load, Nice solutions or so I thought
1st problem a page load occurs during a post back, so the dropdown list was getting populated twice, once during the initial page load, and AGAIN during a validation post back on a textbox
So I decided to clear the dropdown list before adding the items
Some hours of frustration later I discovered the clearing and reloading the list items was not such a good plan, Pageload also goes off during a form submission which then nukes the selectedvalue data for the dropdown list
End result, test the dropdown list item count before to see if I have already added any item, of not add them
Sorted
1. My selected values work properly
2. My postbacks are quicker as the webservices call only occurs on initial load
![]()