Hello everyone,
I'm trying to use a CascadingDropDown in a module, but I have some problems. In a separate test project, all works fine, but when I try to use the same code in a module, the function GetDropDownContents written in the WebService never fires.
Can anyone suggest me a solution?
This is the sample code:
In Control.ascx:
<div >
<div >CascadingDropDown Demonstration</div>
<table>
<tr>
<td>Make</td>
<td><asp:DropDownList ID="DropDownList1" runat="server" Width="170" /></td>
</tr>
<tr>
<td>Model</td>
<td><asp:DropDownList ID="DropDownList2" runat="server" Width="170" /></td>
</tr>
<tr>
<td>Color</td>
<td><asp:DropDownList ID="DropDownList3" runat="server" Width="170" AutoPostBack="true"
OnSelectedIndexChanged="DropDownList3_SelectedIndexChanged" /></td>
</tr>
</table>
<br />
<cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="DropDownList1"
Category="Make" PromptText="Please select a make" LoadingText="[Loading makes...]"
ServicePath="CarsService.asmx" ServiceMethod="GetDropDownContents" />
<cc1:CascadingDropDown ID="CascadingDropDown2" runat="server" TargetControlID="DropDownList2"
Category="Model" PromptText="Please select a model" LoadingText="[Loading models...]"
ServiceMethod="GetDropDownContentsPageMethod" ParentControlID="DropDownList1" />
<cc1:CascadingDropDown ID="CascadingDropDown3" runat="server" TargetControlID="DropDownList3"
Category="Color" PromptText="Please select a color" LoadingText="[Loading colors...]"
ServicePath="CarsService.asmx" ServiceMethod="CarsService.GetDropDownContents"
ParentControlID="DropDownList2" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" RenderMode="inline">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="[No response provided yet]" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList3" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</div>
In Control.ascx.vb
<WebMethod()> _
<System.Web.Script.Services.ScriptMethod()> _
Public Shared Function GetDropDownContentsPageMethod(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
Return New CarsService().GetDropDownContents(knownCategoryValues, category)
End Function
In CarsService.asmx (the service file)
%@ WebService
Language="VB"
CodeBehind="~/App_Code/CarsService.vb"
Class="CarsService" %>
in CarsService.vb (the code-behind service file)
' (c) Copyright Microsoft Corporation.
' This source is subject to the Microsoft Public License.
' See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
' All other rights reserved.
Imports System
Imports System.Collections.Specialized
Imports System.Text.RegularExpressions
Imports System.Web
Imports System.Web.Services
Imports System.Xml
''' <summary>
''' Helper web service for CascadingDropDown sample
''' </summary>
<WebService([Namespace] := "http://tempuri.org/")> _
<WebServiceBinding(ConformsTo := WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
Public Class CarsService
Inherits WebService
' Member variables
Private Shared _document As XmlDocument
Private Shared _inputValidationRegex As Regex
Private Shared _lock As New Object()
' we make these public statics just so we can call them from externally for the
' page method call
Public Shared ReadOnly Property Document() As XmlDocument
Get
SyncLock _lock
If _document Is Nothing Then
' Read XML data from disk
_document = New XmlDocument()
_document.Load(HttpContext.Current.Server.MapPath("~/App_Data/CarsService.xml"))
End If
End SyncLock
Return _document
End Get
End Property
Public Shared ReadOnly Property Hierarchy() As String()
Get
Return New String() {"make", "model"}
End Get
End Property
Public Shared ReadOnly Property InputValidationRegex() As Regex
Get
SyncLock _lock
If _inputValidationRegex Is Nothing Then
_inputValidationRegex = New Regex("^[0-9a-zA-Z \(\)]*$")
End If
End SyncLock
Return _inputValidationRegex
End Get
End Property
''' <summary>
''' Helper web service method
''' </summary>
''' <param name="knownCategoryValues">private storage format string</param>
''' <param name="category">category of DropDownList to populate</param>
''' <returns>list of content items</returns>
<WebMethod()> _
Public Function GetDropDownContents(ByVal knownCategoryValues As String, ByVal category As String) As AjaxControlToolkit.CascadingDropDownNameValue()
' Get a dictionary of known category/value pairs
Dim knownCategoryValuesDictionary As StringDictionary = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)
' Perform a simple query against the data document
Return AjaxControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument(Document, Hierarchy, knownCategoryValuesDictionary, category, InputValidationRegex)
End Function
End Class
thank you!