Solved

asp.net, jquery, autocomplete

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

695 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