JQuery: SP. NET Autocomplete Textbox Using jQuery, JSON and AJAX, jqueryautocomplete

Source: Internet
Author: User

JQuery: SP. NET Autocomplete Textbox Using jQuery, JSON and AJAX, jqueryautocomplete

<% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "jQueryAutocomplete. aspx. cs" Inherits = "VipWinValidation. jQueryAutocomplete" %> <! DOCTYPE html> 

  

/// <Summary> /// $ codebehindclassname $ abstract description /// </summary> [WebService (Namespace =" http://tempuri.org/ ")] [WebServiceBinding (ConformsTo = WsiProfiles. basicProfile1_1)] public class LoadCountry: IHttpHandler {// <summary> //// </summary> /// <param name = "context"> </param> public void ProcessRequest (HttpContext context) {HttpRequest request = context. request; HttpResponse response = context. response; System. collections. specialized. nameValueCollection forms = context. request. form; string strOperation = forms. get ("term"); // List <string> li = Country (strOperation); JavaScriptSerializer JS = new JavaScriptSerializer (); string sf = JS. serialize (li); context. response. write (sf );} /// <summary> ///// </summary> /// <param name = "input"> </param> /// <returns> </returns> private List <string> Country (string input) {// Get the countries list from database, for this example I am creating sample output // return GetCountriesfromDB (input); List <string> li = new List <string> (); foreach (string s in GetCountries () {string st = s. toLower (); if (st. contains (input. toLower () {li. add (s) ;}// Linq // return GetCountries (). findAll (item => item. toLower (). contains (input. toLower (); return li ;} /// <summary> ///// </summary> /// <returns> </returns> private List <string> GetCountries () {List <string> CountryInformation = new List <string> (); CountryInformation. add ("India"); CountryInformation. add ("United States"); CountryInformation. add ("United Kingdom"); CountryInformation. add ("Canada"); CountryInformation. add ("South Korea"); CountryInformation. add ("France"); CountryInformation. add ("Mexico"); CountryInformation. add ("Russia"); CountryInformation. add ("Australia"); CountryInformation. add ("Turkey"); CountryInformation. add ("Kenya"); CountryInformation. add ("New Zealand"); CountryInformation. add ("tu juwen"); CountryInformation. add ("tu Nian Sheng"); CountryInformation. add ("Jiangxi Province"); CountryInformation. add ("Jiangsu Province"); CountryInformation. add ("Zhejiang Province"); return CountryInformation;} // <summary> /// </summary> public bool IsReusable {get {return false ;}}}

. Net 4.0

<% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "jQueryAutocomplete. aspx. cs" Inherits = "DuCms. Web. jQueryAutocomplete" %> <! DOCTYPE html> 

  

Using System; using System. collections. generic; using System. linq; using System. web; using System. web. UI; using System. web. UI. webControls; using System. web. services; namespace DuCms. web {// <summary> ///// </summary> public partial class jQueryAutocomplete: System. web. UI. page {// <summary> //// </summary> /// <param name = "sender"> </param> /// <param name = "e"> </param> protected void Page_Load (object sender, eventArgs e) {} [WebMethod] public static List <string> LoadCountry (string input) {List <string> li = new List <string> (); // Get the countries list from database, for this example I am creating sample output // return GetCountriesfromDB (input); li = GetCountries (). findAll (item => item. toLower (). contains (input. toLower (); return li ;} /// <summary> ///// </summary> /// <returns> </returns> public static List <string> GetCountries () {List <string> CountryInformation = new List <string> (); CountryInformation. add ("India"); CountryInformation. add ("United States"); CountryInformation. add ("United Kingdom"); CountryInformation. add ("Canada"); CountryInformation. add ("South Korea"); CountryInformation. add ("France"); CountryInformation. add ("Mexico"); CountryInformation. add ("Russia"); CountryInformation. add ("Australia"); CountryInformation. add ("Turkey"); CountryInformation. add ("Kenya"); CountryInformation. add ("New Zealand"); CountryInformation. add ("tu juwen"); CountryInformation. add ("tu Nian Sheng"); CountryInformation. add ("Jiangxi Province"); CountryInformation. add ("Jiangsu Province"); CountryInformation. add ("Zhejiang Province"); return CountryInformation ;}}}

  

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.