Reputation: 4893
I want to use AjaxToolKit
AutoComplete
feature.
The syntax for the tag is:
<ajaxToolkit:AutoCompleteExtender ID="autoComplete1" runat="server"
EnableCaching="true"
BehaviorID="AutoCompleteEx"
MinimumPrefixLength="2"
TargetControlID="myTextBox"
ServicePath="AutoComplete.asmx"
ServiceMethod="GetCompletionList"
CompletionInterval="1000"
CompletionSetCount="20"
CompletionListCssClass="autocomplete_completionListElement"
CompletionListItemCssClass="autocomplete_listItem"
CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
DelimiterCharacters=";, :"
ShowOnlyCurrentWordInCompletionListItem="true">
<!-- Some formatting code -->
</ajaxToolkit:AutoCompleteExtender>
There are attribute ServicePath and ServiceMethod which helps tag to fetch data from. The ServiceMethod has schema:
[WebMethod]
public string[] GetCompletionList(string prefixText, int count)
The method expects only two parameters. For some business logic requirement I want to send three parameters to method as:
[WebMethod]
public string[] GetCompletionList(string type, string prefixText, int count)
How can I pass this third parameter and accept it in service method for processing. My results will be dependent on this type parameter. How can I achieve this? Thanks in advance.
Upvotes: 0
Views: 624
Reputation: 101
You can pass a contextKey through as a third argument.
When setting up the ajaxToolkit:AutoCompleteExtender, add the key-value pair UseContextKey="True", eg
<ajaxToolkit:AutoCompleteExtender ID="autoComplete1" runat="server"
UseContextKey="True"
EnableCaching="true"
BehaviorID="AutoCompleteEx"
MinimumPrefixLength="2"
TargetControlID="myTextBox"
ServicePath="AutoComplete.asmx"
ServiceMethod="GetCompletionList"
CompletionInterval="1000"
CompletionSetCount="20"
CompletionListCssClass="autocomplete_completionListElement"
CompletionListItemCssClass="autocomplete_listItem"
CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
DelimiterCharacters=";, :"
ShowOnlyCurrentWordInCompletionListItem="true">
<!-- Some formatting code -->
</ajaxToolkit:AutoCompleteExtender>
Set the context to whatever string you want before the service method is called:
function setContextKey() {
text = 'my type information';
$find('<%=autoComplete1.ClientID%>').set_contextKey(text);
}
Then in your code behind, you have access to that contextKey:
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] GetCompletionList(string prefixText, int count, string contextKey)
{
string myType = contextKey;
}
Upvotes: 1
Reputation: 4854
You cannot add a third parameter. But you can may be read this parameter info by storing and then retrieving it from Session
or Request
, by accessing them from the HttpContext.Current
, since you are in a static method.
Upvotes: 0