?
Solved

asp.net, jquery, autocomplete

Posted on 2014-09-23
3
Medium Priority
?
533 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 2000 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

765 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