I have an ajax autocomplete extender. I want to pass the value of the hidden field to the web service. I want to pass the value of t开发者_运维技巧he hidden field as contextkey parameter to the web service.
If the $find(BehaviorID) return null you can do that way:
// Hook up to the AutoComplete populating/populated events
function pageLoad() {
var autoComplete = getBehavior('AutoCompleteBehavior');
if (!autoComplete) return;
var target = autoComplete.get_element();
if (!target) return;
var userContext = $get('<%=this.ddlColumnName.ClientID %>');
if (!userContext) return;
// Dynamically assign the context and change the color when processing
autoComplete.add_populating(function () {
autoComplete.set_contextKey(userContext.value);
});
autoComplete.add_itemSelected(function () {
_doPostBack('<%=this.ddlColumnName.ClientID %>', '');
});
}
function getBehavior(name) {
//If any Extender is placed in the DataBind Control, it's hard to define the BehaviorId and get the Client behavior.
//We can use the method to find all the correct type behaviors.
var currentBehavior = null;
var allBehaviors = Sys.Application.getComponents();
for (var loopIndex = 0; loopIndex < allBehaviors.length; loopIndex++) {
currentBehavior = allBehaviors[loopIndex];
if ("get_name" in currentBehavior) {
if (currentBehavior.get_name() == name) {
// Now we get the ClientBehavior here: currentBehavior!
return currentBehavior
}
}
}
return
}
I figured it out. I have posted the code below in case some one else has a similar issue.
<asp:Panel id ="divClientSearch" CssClass="clientSearch" runat="server" DefaultButton="btnSearch">
<label>Enter Client Last Name/First Name/Full Name/SSN: </label>
<asp:TextBox ID="txtSearch" runat="server" MaxLength="20" autocomplete="off"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" SkinID="smallButton" OnClick="BtnSearchClick"
OnClientClick="return RedirectPage();" Text="Search" />
<input type="hidden" id="searchClient" runat="server" />
<asp:TextBox ID="searchClient22" runat="server" MaxLength="20" autocomplete="off" Visible="false"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender runat="server" ID="autoComplete1" TargetControlID="txtSearch" BehaviorID="AutoCompleteBehavior"
ServiceMethod="GetClients" ServicePath="~/AjaxServices/TickerSearch.asmx"
MinimumPrefixLength="1" CompletionInterval="1000" EnableCaching="true" CompletionSetCount="200"
CompletionListCssClass="autocomplete_completionListElement menuList" CompletionListItemCssClass="autocomplete_listItem"
CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem" DelimiterCharacters=""
ShowOnlyCurrentWordInCompletionListItem="true">
</ajaxToolkit:AutoCompleteExtender>
</asp:Panel>
<script type="text/javascript">
function pageLoad() {
var autoComplete = $find('AutoCompleteBehavior');
if (!autoComplete) return;
var target = autoComplete.get_element();
if (!target) return;
var userContext = document.getElementById('<%=searchClient.ClientID %>').value;
if (!userContext) return;
// Dynamically assign the context and change the color when processing
autoComplete.add_populating(function() {
autoComplete.set_contextKey(userContext);
});
}
</script>
精彩评论