Solved

asp.net, jquery, autocomplete

Posted on 2014-09-23
3
492 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now