Solved

asp.net, jquery, autocomplete

Posted on 2014-09-23
3
502 Views
Last Modified: 2014-10-02
I have below codes inside of the ascx.cs file. and I want to use jquery autocomplete.
Can you show me how to do that?  I am very new in jquery, and my website currently have no jquery things installed.

Thanks

        [System.Web.Script.Services.ScriptMethod()]
        [System.Web.Services.WebMethod]
        public static string[] GetBrand(string prefixText, int count)
        {
            ServiceContract.Service serviceClient = new ServiceContract.Service();
            List<string> productList = serviceClient.GetProductListByKeyword(prefixText, count);
            var list = from p in productList
                       where p.Contains(prefixText)
                       select p;
            string[] prefixTextArray = list.ToArray<string>();
            return prefixTextArray;
        }

//aspx

<asp:TextBox runat="server" class="search-field"   placeholder="Search for item" ID="searchpart" ></asp:TextBox>
0
Comment
Question by:ITsolutionWizard
  • 2
3 Comments
 
LVL 14

Expert Comment

by:dejaanbu
ID: 40340845
just reference jquery files.
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/redmond/jquery-ui.css" />
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>

Open in new window

or your can download from http://jquery.com/download/ and http://jqueryui.com/
then call the autocomplete function inside script tags
<script type="text/javascript">
$(function() {
    
            $("#<%=searchpart.ClientID%>").autocomplete({
                source: "youraspxfilename.aspx" //aspx or ashx file where you have the webmethod
           });
});
</script>

Open in new window

you can find more examples in the web.
http://www.aspsnippets.com/Articles/Populate-jQuery-AutoComplete-TextBox-from-Database-using-Web-Service-in-ASPNet.aspx
http://dotnetmentors.com/aspnet/jquery-autocomplete-by-example.aspx
0
 

Author Comment

by:ITsolutionWizard
ID: 40342826
Below codes stayed in .cs same as client page which is ascx. so the textbox asp.net in default.ascx and below codes is in default.ascx.cs...in this case

what should I put in below codes?

source: "youraspxfilename.aspx"



 [System.Web.Script.Services.ScriptMethod()]
        [System.Web.Services.WebMethod]
        public static string[] GetBrand(string prefixText, int count)
        {
            ServiceContract.Service serviceClient = new ServiceContract.Service();
            List<string> productList = serviceClient.GetProductListByKeyword(prefixText, count);
            var list = from p in productList
                       where p.Contains(prefixText)
                       select p;
            string[] prefixTextArray = list.ToArray<string>();
            return prefixTextArray;
        }
0
 
LVL 14

Accepted Solution

by:
dejaanbu earned 500 total points
ID: 40343307
i am not sure about having the webmethod inside the ascx. you can put your method in any page, it can be a separate wsmx/ashx/aspx file. And just give the correct path in the Source: parameter.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question