Automatic implementation (Ajax, jqueyr, webserver)

Source: Internet
Author: User

1. the Ajax implementation method is as follows:
Webpage:

<asp:ScriptManager ID="ScriptManager1" runat="server"/><cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" ServiceMethod="CusName" ServicePath="AutoService.asmx"TargetControlID="customer" MinimumPrefixLength="1" EnableCaching="true" ></cc1:AutoCompleteExtender>

Webserver:

[Webmethod] Public String [] cusname (string prefixtext) {webclass. list TMP = new webclass. list (); dbdatareader DR = TMP. showname (prefixtext); List <string> suggestions = new list <string> (); // declare a generic set while (dr. read () {suggestions. add (dr. getstring (0);} Dr. close (); Return suggestions. toarray ();}

2. The jquer implementation method is as follows:
Project to be introduced:

    <link href="css/jquery.autocomplete.css" rel="stylesheet" type="text/css" />    <script language="JavaScript" type="text/javascript" src="js/jquery.js"></script>    <script language="JavaScript" type="text/javascript" src="js/jquery.autocomplete.js"></script>
jvascript:
$(document).ready(function(){    $("#contactperson").autocomplete("AutoHandler.ashx",{        delay:10,        minChars:2,        matchSubset:1,        cacheLength:1,        onItemSelect:selectItem,        onFindValue:findValue,        autoFill:true,        maxItemsToShow:20    });  }); 

Ashx:

Public void processrequest (httpcontext context) {// context. response. contenttype = "text/plain"; // context. response. write ("Hello World"); string prefixtext = context. request. querystring ["Q"]; webclass. rfslist TMP = new webclass. rfslist (); dbdatareader DR = TMP. showcusname (prefixtext); stringbuilder items = new stringbuilder (); While (dr. read () {items. append (dr. getstring (0) + "\ n");} Dr. close (); context. response. write (items. tostring (); context. response. end ();}
Similar to the aspx webpage, CSS is as follows:
.ac_results {padding: 0px;border: 1px solid WindowFrame;background-color: Window;overflow: hidden;}.ac_results ul {width: 100%;list-style-position: outside;list-style: none;padding: 0;margin: 0;}.ac_results iframe {display:none;/*sorry for IE5*/display/**/:block;/*sorry for IE5*/position:absolute;top:0;left:0;z-index:-1;filter:mask();width:3000px;height:3000px;}.ac_results li {margin: 0px;padding: 2px 5px;cursor: pointer;display: block;width: 100%;font: menu;font-size: 12px;overflow: hidden;}.ac_loading {background : Window url('../img/onload.gif') right center no-repeat;}.ac_over {background-color: Highlight;color: HighlightText;}

Jquery and jquery AutoComplete will not be pasted.
/Files/cnaspnet/jqueryautocomplete.rar

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.