views:

286

answers:

0

Greetings, I'm having an issue with a cascading dropdown not updating correctly server-side.

The page I am using has two cascading dropdowns: one for the category of a car [ddlCategory] and one for the colors of a car of a certain category [ddlColor]. There are also two text fields that take dates. The goal of the page is to display an overview of available vehicles between those two dates, so people can rent them.

Everything appears to work correctly, but a bug occurs when I do the following:

  1. Select a category from ddlCategory.
  2. Fill in valid dates in both text fields.
  3. Select a car color from ddlColor.

And this is where it goes wrong:

  1. Change the category in ddlCategory to another one.

Client-side, everything is reloaded correctly and appears to have selected the first value automatically. Server-side, however, it goes wrong, more precisely at the following line of code:

Private Sub ChangeOverview()
        Dim category As String = Me.ddlCategory.SelectedValue
        Dim begindate As Date = Me.txtBegindate.Text
        Dim enddate As Date = Me.txtEnddate.Text
        Dim color As String = Me.ddlColor.SelectedItem.Text <---- THE CULPRIT

        [Snipped out some code that does the overview creation]
End Sub

ddlColor still thinks it is using the previous list contents, and hence shows wrong values. Things I have tried to do to remove or mitigate the problem (all have failed):

  • Reset the values to default client- and server-side with the appropriate code. (see link)
  • Manually update the UpdatePanel to get a content update from the browser.
  • Use System.Threading.Thread.Sleep() to give the system some time to update.

So, does anyone know of a reliable way to update my server-side content before it runs the ChangeOverview() sub?

Notes:

  • The Cascading Dropdowns communicate with a web service.
  • ChangeOverview is called on every control mentioned here.
  • ddlCategory_SelectedIndexChanged also contains ResetddlColor() and an UpdatePanel update command, both of which are listed above ChangeOverview().

Many thanks in advance.