how do I pass additional information to the service method returning the collection of items? I’ll attempt to explain what I mean, I have 2 text boxes on a form, I need to fill out names, based of a specific account id in a database. so, I need to pass an integer to the getNamesForDropDown method. I couldn’t figure out what to do, so I did the wrong thing, and used the CompletionSetCount to actually pass the information I needed:
[System.Web.Services.WebMethod] [System.Web.Script.Services.ScriptMethod] public string[] getNamesForDropDown(string prefixText, int count) { String sql = 'Select fldName From idAccountReps Where idAccount = ' + count.ToString(); //... rest of the method removed, this should be enough code to understand //... the evil wrongness I did. }
in my front side aspx file, i set the CompletionSetCount based off the Account id the user is currently viewing on that page.
<ajaxtk:AutoCompleteExtender runat='server' ID='AC1' TargetControlID='txtAccName' ServiceMethod='getNamesForDropDown' ServicePath='AccountInfo.asmx' MinimumPrefixLength='1' EnableCaching='true' CompletionSetCount='<%# Eval('idAccount') %>' />
So, that’s definitely a wrong way… what would be the right way?
azam has the right idea- but the signature of the autocomplete method can also have a third parameter:
public string[] yourmethod(string prefixText, int count, string contextKey)
you can Split up the results of the contextKey string using Azam’s method- but this way you do not have to worry about sanatizing the user’s input of the .Split()’s delimiter (:)