Hi,
I have created an ajax autocomplete extender control and a web service. It's all working very well, until I want to use the same webservice for all my lists using a ContextKey to send the name of the list to the web service. When adding the ContextKey, the webservice is not even called.
I am using Framework 3.5
The Ajaxcontroltoolkit dll in my project is 3.5 40412.2
Tested in Internet Explorer 7
Thank you for your help
The following code is not working (with ContextKey):
aspx page:
<asp:TextBox ID="TextBox1" runat="server" AutoComplete="Off"/>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" UseContextKey="True" ContextKey="Deus Contact"
TargetControlID="TextBox1" ServicePath="Combo.asmx" ServiceMethod="GetList" MinimumPrefixLength="2" EnableCaching="true"
Enabled="true" CompletionInterval="10" CompletionSetCount="10"/>
Web service:
<WebMethod()> _
Public Function GetList(ByVal prefixText As String, ByVal count As Integer, ByVal ContextKey As String) As String()
Dim strSQL As String = ""
Select Case ContextKey
Case "Deus Contact", "Comm Contact Type", "Comm Search List"
strSQL = "EXEC COMM_sp_List @Type='" & ContextKey & "', @Selection='" & prefixText & "'"
Case "App Round"
strSQL = "EXEC APP_sp_List @Type='" & ContextKey & "', @Selection='" & prefixText & "'"
End Select
Dim CN As SqlConnection = New SqlConnection(ConnectionStrings(AppSettings("WesfapDBKey")).ConnectionString)
If CN.State = ConnectionState.Closed Then CN.Open()
Dim cmd As SqlCommand = New SqlCommand(strSQL, CN)
Dim dtr As SqlDataReader = cmd.ExecuteReader()
Dim Results As New ArrayList
Try
Dim Counter As Integer
While dtr.Read
If (Counter = count) Then Exit While
Results.Add(dtr("cboDesc").ToString())
Counter += 1
End While
Dim ResultsArray(Results.Count - 1) As String
ResultsArray = Results.ToArray(GetType(System.String))
Return ResultsArray
Catch ex As Exception
Throw ex
End Try
End Function
When the following code is working (without ContextKey):
aspx page:
<asp:TextBox ID="TextBox1" runat="server" AutoComplete="Off"/>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
TargetControlID="TextBox1" ServicePath="Combo.asmx" ServiceMethod="GetList" MinimumPrefixLength="2" EnableCaching="true"
Enabled="true" CompletionInterval="10" CompletionSetCount="10"/>
Web service:
<WebMethod()> _
Public Function GetList(ByVal prefixText As String, ByVal count As Integer) As String()
Dim strSQL As String = ""
Dim ContextKey As String = "Deus Contact"
Select Case ContextKey
Case "Deus Contact", "Comm Contact Type", "Comm Search List"
strSQL = "EXEC COMM_sp_List @Type='" & ContextKey & "', @Selection='" & prefixText & "'"
Case "App Round"
strSQL = "EXEC APP_sp_List @Type='" & ContextKey & "', @Selection='" & prefixText & "'"
End Select
Dim CN As SqlConnection = New SqlConnection(ConnectionStrings(AppSettings("WesfapDBKey")).ConnectionString)
If CN.State = ConnectionState.Closed Then CN.Open()
Dim cmd As SqlCommand = New SqlCommand(strSQL, CN)
Dim dtr As SqlDataReader = cmd.ExecuteReader()
Dim Results As New ArrayList
Try
Dim Counter As Integer
While dtr.Read
If (Counter = count) Then Exit While
Results.Add(dtr("cboDesc").ToString())
Counter += 1
End While
Dim ResultsArray(Results.Count - 1) As String
ResultsArray = Results.ToArray(GetType(System.String))
Return ResultsArray
Catch ex As Exception
Throw ex
End Try
End Function
ASKER