AutoCompleteExtender works sometimes

    [System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public string[] GetRowsByFilter(string prefixText, int count)
    //public static List<string> GetRowsByFilter(string prefixText)
    {
        DataTable table = ds.Tables[0];
        string filter = "stShortName LIKE '" + prefixText.Replace("'", "''") + "%'";
        DataRow[] foundRows;
        List<string> items = new List<string>(count);

        foundRows = table.Select(filter);
        if (foundRows.Length > 0)
        {
             for (int i = 0; i < foundRows.Length; i++)
            {
                items.Add((string)foundRows[i]["stShortName"]);
            }
            return items.ToArray();
        }
        else
        {
            items.Add("No '" + prefixText + "' items found");
            return items.ToArray();
        }
    }

      

and

<ajaxToolkit:AutoCompleteExtender 
    id="AutoCompleteExtenderTxtSite" 
    BehaviorID="AutoCompleteEx"
    Runat="server" 
    Targetcontrolid="txtSiteASP"
    ServiceMethod="GetRowsByFilter"
    MinimumPrefixLength="1" 
    CompletionInterval="1000"
    EnableCaching="false"
    CompletionSetCount="10" 
    CompletionListCssClass="autocomplete_completionListElement" 
    CompletionListItemCssClass="autocomplete_listItem" 
    CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
    DelimiterCharacters=";, :"
    ShowOnlyCurrentWordInCompletionListItem="true" 
  >
    <Animations>
        <OnShow>
            <Sequence>
                <OpacityAction Opacity="0" />
                <HideAction Visible="true" />
                <ScriptAction Script="
                    // Cache the size and setup the initial size
                    var behavior = $find('AutoCompleteEx');
                    if (!behavior._height) {
                        var target = behavior.get_completionList();
                        behavior._height = target.offsetHeight - 2;
                        target.style.height = '0px';
                    }" />
                <Parallel Duration=".4">
                    <FadeIn />
                    <Length PropertyKey="height" StartValue="0" EndValueScript="$find('AutoCompleteEx')._height" />
                </Parallel>
            </Sequence>
        </OnShow>
        <OnHide>
            <Parallel Duration=".4">
                <FadeOut />
                <Length PropertyKey="height" StartValueScript="$find('AutoCompleteEx')._height" EndValue="0" />
            </Parallel>
        </OnHide>
    </Animations>
</ajaxToolkit:AutoCompleteExtender>

      

Most are straight from the Toolkit website. I also did it using a web service in exactly the same way as from the example, except for populating the array from the database. Both fill the array flawlessly and both work sometimes. Lack of performance wise, they seem to be the same.

I use a couple of calendar controls on a different page and they work flawlessly, but spent too much time trying to make it work consistently.

-4


source to share


1 answer


I found that if the server side code takes a long time, the client AJAX request seems to time out.

I didn't try to prove it because the effort seemed more than worthwhile when I could just tweak the server-side code to improve performance.



Check if your DataSet is cached, and if not, how long does it take to get it? Check your database indexes. Sql LIKE queries are better optimized in SQL Server 2005.

In case it is not a timeout and is actually a server side error, either check the web service locally by accessing it through a browser and enter the requests you will use in the autocomplete text box. Alternatively, check the server event log immediately after you get no results and look for ASP.NET event warnings.

+1


source







All Articles