CascadingDropDown ViewState Problem
- by Steven
I have two Ajax CascadingDropDown extenders on my page. After a postback, the value of the first dropdown is set (presumably) triggering an event for the second dropdown to refresh.
Question: How do I maintain both the contents (from queries) and selected value of both dropdowns after postback?
C# answers also welcome.
Default.aspx
Active States<br /><asp:DropDownList ID="StatesDrop" runat="server" /><br />
Active Cities<br /><asp:DropDownList ID="CitiesDrop" runat="server" /><br />
<ajax:CascadingDropDown ID="StatesCasc" TargetControlID="StatesDrop"
ServicePath="WebService1.asmx" ServiceMethod="GetActiveStates"
Category="States" runat="server"
PromptText="Select a State" PromptValue="?" />
<ajax:CascadingDropDown ID="CitiesCasc" TargetControlID="CitiesDrop"
ServicePath="WebService1.asmx" ServiceMethod="GetActiveCities"
Category="Cities" runat="server" ParentControlID="StatesDrop"
PromptText="Select a City" PromptValue="?" />
WebService1.asmx.vb
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Web.Script.Services
Imports AjaxControlToolkit
<System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding _
(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class WebService1: Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function GetActiveStates (ByVal knownCategoryValues As String, _
ByVal category As String) As CascadingDropDownNameValue()
Dim values As New List(Of CascadingDropDownNameValue)()
'Populate values with query'
Return values.ToArray()
End Function
<WebMethod()> _
Public Function GetActiveCities (ByVal knownCategoryValues As String, _
ByVal category As String) As CascadingDropDownNameValue()
Dim kv As StringDictionary = _
CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)
Dim SelState As String = ""
If kv.ContainsKey("State") Then SelState = kv("State")
Dim values As New List(Of CascadingDropDownNameValue)()
' Populate values with query.'
Return values.ToArray()
End Function
End Class