Avatar of AnneF
AnneF

asked on 

Ajax autocomplete control - using contextkey

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



AJAXASP.NETWeb Development

Avatar of undefined
Last Comment
AnneF
ASKER CERTIFIED SOLUTION
Avatar of AnneF
AnneF

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of AnneF
AnneF

ASKER

Nobody has given me any answers, and this is the correct solution.
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo