Link to home
Start Free TrialLog in
Avatar of npl77
npl77

asked on

Adding More Parameters To Ajax Auto Complete

I am using the ajax auto complete extender that is connected to a webService called findName (code is shown below) I want to add 2 more input parameters to the web service to pass the data for the 2 session variables you see.  Is this possible? If so how do I hook it up in the control?

The webservice doesnt see the session variables for some reason. Is there a way for the web service to see the session variables? that would fix the problem.
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class WebService
    Inherits System.Web.Services.WebService

    <WebMethod()> _
        <System.Web.Script.Services.ScriptMethod()> _
        Public Function FindName(ByVal prefixText As String, ByVal count As Integer) As String()
        'return all records whose Title starts with the prefix input string 
        Dim titleArList As New List(Of String)()


        'Dim dt As DataTable = SiteAccess.GetMembers()
        'For i As Integer = 1 To dt.Rows.Count - 1

        '    Dim s As String = dt.Rows(i)("lastname").ToString()
        '    If s.StartsWith(prefixText.ToUpper()) Then
        '        titleArList.Add(s)
        '    End If
        'Next


        Dim dt As DataTable = SiteAccess.GetMembersByPrefix(prefixText, Session("user").ToString(), Session("role").ToString())
        For i As Integer = 0 To dt.Rows.Count - 1
            Dim s As String = dt.Rows(i)("EMPLNM").ToString()
            titleArList.Add(s)
        Next

        Return titleArList.ToArray()
    End Function
End Class

Open in new window

Avatar of silemone
silemone
Flag of United States of America image

you can't...those controls you have to use the exact signature that you see in all examples and vids...you would probably have to create a custom control to change that...
Avatar of Miguel Oz
You need to pass the session variables as primitive types (string, int).
Just add the parameter to your web service and it will work fine.
FindName(ByVal prefixText As String, ByVal count As Integer, ByVal session1 As String, ByVal session2 As String) As String()

Usage:
Dim session1 as String = CType(Session.Item("session1 "), String)
'the use session1 in you ws call
Avatar of npl77
npl77

ASKER

I cannot add a parameter to the web service because an ajax control has to use that exact signature. And I cant access the session variable from within the webservice right mas oz2003?
Correct, the session variables only exists for your user's web site.
http://msdn.microsoft.com/en-us/library/ms178581.aspx

Any particular reason that you can not change the web service parameters, the web service is independent of your website anyway. The Ajax control is just another client trying to use your web service.
Ok, if you can not change the web service at all your only chance is to store your variables in a file, so that your web service can read the file and fecth the values from there.
Very messy and unreliable, to be honest...
and yes, sessions are not seen by services...that was one of the limitations of the toolkit...

you can either change the toolkit javascript, create custom class...(a lot of work...) that's why they ship files, site, etc..with toolkit...so you can update it, modify it, compile it and take the new dll...its limited, but its a starting point...on this, however, rather than read through all of that code, i would suggest just using a straight javascript/ajax or jquery/ajax solution...
one more thing you may be able to do:

place a public property in  you webservice...and before calling  your webservice method, you can set the property of that field...

such as:

public int x{
set;
get;
}
Avatar of npl77

ASKER

The problem is I am not programmatically calling the web service all I do to make the control work is set the service name of the autocomplete extender control. So as I know of I have no way to set a property. If attempting to recreate the autocomplete control itself is alot of work it wont be worth it. So I guess there isnt really anyway to get the parameters to my GetMembersByPrefix function that sucks. I guess I just found out the hardway of the limitations using the ajax toolkit.
ASKER CERTIFIED SOLUTION
Avatar of silemone
silemone
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So I guess there isnt really anyway to get the parameters to my GetMembersByPrefix function that sucks. I guess I just found out the hardway of the limitations using the ajax toolkit.  <----

yes, not without massaging it with some coding...
Avatar of npl77

ASKER

lol thanks for the work around. That should work, I like your thinking. Thanks!
Avatar of npl77

ASKER

Oh no! Jumped the gun too fast. Can you give me sample javascript to accomplish this. What I realized is I have no control over the textbox either again with the auto complete control I just set a parameter of the textbox it is to control. Can you give me an example of how the extender is gonna pick up the code to append the parameter values to the Text.
yeah its a hack job, but sometimes its all we can do to get production completed quickly.

good luck with the  project.

cheers.
hey...do you have a webservice?  is it on the same page or in webservices?
i.e. is it a webservice   asmx  (<-- webservice)
   or within you code-behind or .aspx page in a script tag (<--webmethod)?

I think we were killing ourselves for nothing...
webmethods should solve this...

place the webservice code in your aspx page in a script tag...the language will be either C# or vb.net...if your code-behind page has          .cs  then c#, else vb --> then visualbasie

see the example...

http://geekswithblogs.net/frankw/archive/2008/03/13/asp.net-ajax-callbacks-to-web-methods-in-aspx-pages.aspx

this way, you can just place a hiddenfield in your page and that webmethod, since its part of the page will see it...should even see a session variable...

                     
i'll walk you through this...
here's a second example with webmethod in the code-behind page...
http://www.ajaxprojects.com/ajax/tutorialdetails.php?itemid=777
Avatar of npl77

ASKER

its an asmx with the .vb portion in the appCode folder
Avatar of npl77

ASKER

I am not suremI will be able to do this maybe you can tell me. I created a usercontrol called AutoSearch this control is a simple control with a textbox and the auto complete extender. What uses this control is not aspx pages but other ascx userControls