2

在我的应用程序中,我在该扩展器中添加了 ajax 自动完成扩展器,我使用了“OnClientPopulated”事件,对于该事件,我在 javascript 中编写了一个函数,它适用于 IE、Chrome、Safari 但不适用于 firefox,因为该事件无法在 firefox 中触发,以下我在那里写的代码:

<ajax:AutoCompleteExtender OnClientPopulated="getSearch_Populated"  ID="AutoCompleteExtenderSearch"
        runat="server" TargetControlID="txtSearchbox" MinimumPrefixLength="1" Enabled="true"
        EnableCaching="true" CompletionSetCount="12" CompletionInterval="1000" ServiceMethod="GetAppNames"
        ServicePath="~/AutoComplete.asmx" DelimiterCharacters="" UseContextKey="true"
        CompletionListCssClass="AutoExtender" CompletionListHighlightedItemCssClass="AutoExtenderHighlight"
        CompletionListItemCssClass=".AutoExtenderList" OnClientItemSelected="selected_Search">
</ajax:AutoCompleteExtender>

JavaScript:

function getSearch_Populated(sender, e) {

    var searchList = sender.get_completionList().childNodes;
    var searchText = sender.get_element().value;
    for (var i = 0; i < searchList.length; i++) {
        var search = searchList[i];
        var searchValueArray = (search._value).split("|");
        var searchId = searchValueArray[0];
        var searchUrl = searchValueArray[1];
        var link = document.createElement('a');
        var href = document.createAttribute('href');
        link.setAttribute('href', searchUrl);
        link.innerText = searchId;
        search.appendChild(link);            
    }
}
4

1 回答 1

0

它在 Firefox 中非常适合我。我是这样做的:

<asp:TextBox ID="TBAjaxSzallitasiCim" runat="server" Text="<%$Resources:WLO_Web,lbl_kereso %>"
    Style="font-style: italic" Width="250"></asp:TextBox><cc1:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender"
        runat="server" ServicePath="AutoCompleteFeeder.asmx" ServiceMethod="Cimvalaszto"
        TargetControlID="TBAjaxSzallitasiCim" CompletionListCssClass="autocomplete_completionListElement"
        CompletionListItemCssClass="autocomplete_listItem" CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
        CompletionInterval="1000" DelimiterCharacters=";" CompletionSetCount="10" FirstRowSelected="true"
        EnableCaching="true" Enabled="true" OnClientPopulating="ShowImage" OnClientPopulated="HideImage"
        OnClientItemSelected="ace0_itemSelected">
    </cc1:AutoCompleteExtender>
<asp:HiddenField ID="ace0Value" runat="server" />

Javascript:

function ShowImage() {
document.getElementById('ctl00_ContentPlaceHolder1_TBAjaxSzallitasiCim')
  .style.backgroundImage = 'url(Images/circle-ball-dark-antialiased.gif)';

document.getElementById('ctl00_ContentPlaceHolder1_TBAjaxSzallitasiCim')
                .style.backgroundRepeat = 'no-repeat';

document.getElementById('ctl00_ContentPlaceHolder1_TBAjaxSzallitasiCim')
                .style.backgroundPosition = 'right';
}

function HideImage() {
document.getElementById('ctl00_ContentPlaceHolder1_TBAjaxSzallitasiCim')
                  .style.backgroundImage = 'none';
}

我正在使用这个库:

<%@ Register TagPrefix="cc1" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit, Version=3.5.51116.0, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e" %>

而这个脚本管理器:

<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" CombineScripts="false"
    AsyncPostBackTimeout="300" EnableHistory="true" EnablePageMethods="true">
</cc1:ToolkitScriptManager>
于 2012-08-23T13:09:41.817 回答