We help IT Professionals succeed at work.
Get Started

Ajax autocomplete control - using contextkey

AnneF
AnneF asked
on
941 Views
Last Modified: 2012-05-11
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



Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE