troubleshooting Question

Ajax autocomplete control - using contextkey

Avatar of AnneF
AnneF asked on
AJAXASP.NETWeb Development
2 Comments1 Solution945 ViewsLast Modified:
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 CERTIFIED SOLUTION
AnneF

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros