Solved

asp.net, jquery, autocomplete

Posted on 2014-09-23
3
512 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
 
LVL 1

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
c# deserialize JSON from web service using JsonConvert 9 53
WPF and Powershell button hover change text 5 58
What are MicroServices? 4 66
CSS styling problem 3 23
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

737 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