Last post Oct 28, 2009 11:42 AM by linick
Aug 27, 2009 05:36 AM|MattPurland|LINK
I've come across a strange problem which hopefully someone can help me with. I'll do my best to explain this as best as I can, but I'm pretty new to this stuff so I apologise if it doesn't make sense.
The scenario is: I have 3 input controls (a text box with a Calendar extendar, and 2 dropdown lists) within an update panel. The 2 dropdown lists are disabled. The 1st dropdown list is enabled when the textbox text is changed (TextChanged) and is populated
using a SqlDataSource within that event. The 2nd dropdownlist is enabled and populated by the same SqlDataSource with a different select string when the 1st dropdown list has an index change (SelectedIndexChanged) - this is where the problem lies. Even though
the code within the SelectedIndexChanged is run through, it doesn't actually render on the screen. For example, the event disables some other labels and enables the 2nd dropdown list, but this isn't rendered on the page.
Hopefully that makes sense. Everything renders fine if the 2nd dropdown list isn't populated by the sqldatasource (simply comment out the code) - see below for the codebehind:
Protected Sub cdrTextBox_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cdrTextBox.TextChanged
If cdrTextBox.Text.Contains("Monday") Then
lblTime.Visible = False
lblAgency.Visible = True
cbChargable.Enabled = True
ddlAgency.Enabled = True
SelectAgencies = Replace(SelectAgencies, "#username", User.Identity.Name.ToString)
AdminDataSource.SelectCommand = SelectAgencies
ddlAgency.DataSourceID = "AdminDataSource"
cdrCustomValidator.IsValid = False
Protected Sub ddlAgency_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlAgency.SelectedIndexChanged
lblAgency.Visible = False
ddlMerchant.Enabled = True
lblMerchant.Visible = True
SelectMerchants = Replace(SelectMerchants, "#agencyid", ddlAgency.SelectedValue)
AdminDataSource.SelectCommand = SelectMerchants
ddlMerchant.DataSourceID = "AdminDataSource"
cdrTextBox = textbox with calendar extendar
ddlAgency = 1st dropdown list
ddlMerchant = 2nd dropdown list
Thanks for any help,
Oct 28, 2009 11:42 AM|linick|LINK
Make sure that the UpdateMode property of UpdatePanel is "Always".
Add the code to refresh the UpdatePanel in the selectedindexchanged event: