0
Reply

Load DropDownList Dynamically In UpdatePanel Causes ViewState Error

Algo Rhythm

Algo Rhythm

Jan 18 2011 12:21 PM
7.6k
Hello, I am trying to dynamically populate a second dropdownlist based on value of first dropdownlist in updatepanel.  However, I get error that says "Failed to load viewstate"  Code works fine without update panel. 
 
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="CtyDropDown" runat="server" AutoPostback="true" OnSelectedIndexChanged="BindDistrictDropdown" />
<asp:DropDownList ID="DistrictDropDown" runat="server" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="CtyDropDown" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
<asp:Button ID="AddCtyBtn" runat="server" Text="Add City/County"/>
 
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Dim sfb As New SFBLogic

CongDistDataList.DataSource = sfb.GetCongressDistrictInfo(1)
CongDistDataList.DataBind()
CongDistDropDown.DataSource = sfb.GetAllCongressionalDistricts
CongDistDropDown.DataTextField =
"CongressionalDistrict"
CongDistDropDown.DataValueField =
"CongressionalDistrict"
CongDistDropDown.DataBind()
CtyDropDown.DataSource = sfb.GetAllCitiesAndCounties()
CtyDropDown.DataTextField =
"Name"
CtyDropDown.DataValueField =
"CityCountyID"
CtyDropDown.SelectedIndex = 1
CtyDropDown.DataBind()
DistrictDropDown.DataSource = sfb.GetCtyDistricts(1)
DistrictDropDown.DataValueField =
"DistrictID"
DistrictDropDown.DataBind()
End Sub