• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 500
  • Last Modified:

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

0
npl77
Asked:
npl77
  • 10
  • 6
  • 3
1 Solution
 
silemoneCommented:
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...
0
 
Miguel OzSoftware EngineerCommented:
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
0
 
npl77Author Commented:
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?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Miguel OzSoftware EngineerCommented:
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.
0
 
Miguel OzSoftware EngineerCommented:
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...
0
 
silemoneCommented:
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...
0
 
silemoneCommented:
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;
}
0
 
npl77Author Commented:
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.
0
 
silemoneCommented:
ohh..gotcha...so you're not doing any javascript...plus its made that way for quickness..sorry, but if your want the functionality you're  seeking, you will have to create this one using javascript....

here's an idea...
1)
if you can do a small bit of coding...whenever the user types into the textbox --> send the text, but also add the text you want to send over as a new paramm...

i.e.   they type:  hello
in the code behind... pass over as the param:

textbox.text + " ---- " + paramIWantToPass

in the webservice, look for the ----, split the word on those '----'

first word being the original text, second part being param you want to pass...

you will have to code, either in Javascript or serverside language....

or

2)
 You will have to use Ajax/javascript -- add property to webservice, update webservice properties with javascript/ajax, and then let the rest of the code happen as it already does...
0
 
silemoneCommented:
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...
0
 
npl77Author Commented:
lol thanks for the work around. That should work, I like your thinking. Thanks!
0
 
npl77Author Commented:
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.
0
 
silemoneCommented:
yeah its a hack job, but sometimes its all we can do to get production completed quickly.

good luck with the  project.

cheers.
0
 
silemoneCommented:
hey...do you have a webservice?  is it on the same page or in webservices?
0
 
silemoneCommented:
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...

                     
0
 
silemoneCommented:
i'll walk you through this...
0
 
silemoneCommented:
here's a second example with webmethod in the code-behind page...
http://www.ajaxprojects.com/ajax/tutorialdetails.php?itemid=777
0
 
npl77Author Commented:
its an asmx with the .vb portion in the appCode folder
0
 
npl77Author Commented:
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
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 10
  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now