<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="jQueryAutocomplete.aspx.cs" Inherits="VipWinValidation.jQueryAutocomplete" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>编辑管理员</title>
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,initial-scale=1.0,user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<link href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" rel="Stylesheet" type="text/css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#<% =txtCountry.ClientID%>").autocomplete({
source: function( request, response ) {
$.ajax({
url: "LoadCountry.ashx",
type: "POST",
dataType: "json",
data: {term: request.term},
success: function(data) {
response(data);
}
});
}
});
});
</script> </head>
<body>
<form id="form1" runat="server">
<div>
Country :
<asp:TextBox ID="txtCountry" runat="server">
</asp:TextBox>
</div>
</form>
</body>
</html>

  

/// <summary>
/// $codebehindclassname$ 的摘要说明
///
/// </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("涂聚文");
CountryInformation.Add("涂年生");
CountryInformation.Add("江西省");
CountryInformation.Add("江苏省");
CountryInformation.Add("浙江省");
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>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>编辑管理员</title>
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,initial-scale=1.0,user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<link href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" rel="Stylesheet" type="text/css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function () {
$("#<% =txtCountry.ClientID%>").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "jQueryAutocomplete.aspx/LoadCountry",
data: "{input:'" + request.term + "'}",
dataType: "json",
success: function (output) {
response(output.d);
},
error: function (errormsg) {
alert(errormsg.responseText);
}
});
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
Country :
<asp:TextBox ID="txtCountry" runat="server">
</asp:TextBox>
</div>
</form>
</body>
</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("涂聚文");
CountryInformation.Add("涂年生");
CountryInformation.Add("江西省");
CountryInformation.Add("江苏省");
CountryInformation.Add("浙江省");
return CountryInformation;
}
}
}

  

jQuery:SP.NET Autocomplete Textbox Using jQuery, JSON and AJAX的更多相关文章

  1. 【jQuery】jquery-ui autocomplete智能提示

    jQuery UI,简而言之,它是一个基于jQuery的前端UI框架.我们可以使用jQuery + jQuery UI非常简单方便地制作出界面美观.功能强大.跨浏览器兼容的前端html界面. Auto ...

  2. jQuery Validate 插件验证,,返回不同信息(json remote)自定义

    问题 申请账号需要确认该账号是存在 jquery.validate.js中的remote Jquery Ajax获取后台返回的Json数据后,添加自定义校验 解题思路:输入的登陆信息远程验证是否该账号 ...

  3. struts2:使用JQuery、JSON和AJAX处理请求

    目的 在struts2中使用JQuery.JSON.AJAX等技术处理用户请求,并返回结果.返回结果可以是以JSONObject的方式返回,也可以是以JSONArray方式返回结果. 实现 1. 创建 ...

  4. 弹窗中使用jquery ui的autocomplete自动完成插件无效果 实际是被遮挡了

    在普通页面上使用jquery ui的autocomplete自动完成插件时正常显示提供选择的下拉框,但是放到弹窗中的时候就无法显示这个选择的下拉框,其它效果正常: 估计是被弹出窗遮挡了,网络搜索了jq ...

  5. jquery 自动完成 Autocomplete插件汇总

    1. jQuery Autocomplete Mod jQuery Autcomplete插件.能够限制下拉菜单显示的结果数. 主页:http://www.pengoworks.com/worksho ...

  6. 不定义JQuery插件,不要说会JQuery 分类: JavaScript 2014-11-24 14:18 155人阅读 评论(0) 收藏

    一:导言 有些WEB开发者,会引用一个JQuery类库,然后在网页上写一写$("#"),$("."),写了几年就对别人说非常熟悉JQuery.我曾经也是这样的人 ...

  7. [转]不定义JQuery插件,不要说会JQuery

    一:导言 有些WEB开发者,会引用一个JQuery类库,然后在网页上写一写("#"),("."),写了几年就对别人说非常熟悉JQuery.我曾经也是这样的人,直 ...

  8. 不定义JQuery插件,不要说会JQuery

    转自:http://www.cnblogs.com/xcj26/p/3345556.html 一:导言 有些WEB开发者,会引用一个JQuery类库,然后在网页上写一写$("#") ...

  9. aspx中的表单验证 jquery.validate.js 的使用 以及 jquery.validate相关扩展验证(Jquery表单提交验证插件)

    这一期我们先讲在aspx中使用 jquery.validate插件进行表单的验证, 关于MVC中使用 validate我们在下一期中再讲     上面是效果,下面来说使用步骤 jQuery.Valid ...

随机推荐

  1. Unity全面的面试题(包含答案)

    一:什么是协同程序? 在主线程运行的同时开启另一段逻辑处理,来协助当前程序的执行,协程很像多线程,但是不是多线程,Unity的协程实在每帧结束之后去检测yield的条件是否满足. 二:Unity3D中 ...

  2. [UWP]缓存Lottie动画帧

    在上一篇博文<[UWP]在UWP平台中使用Lottie动画>中我简单介绍了一下LottieUWP项目以及如何使用它呈现Lottie动画,这篇文章里我们来讲点进阶的东西--缓存Lottie动 ...

  3. 不修改模板的前提下修改VisualState中的某些值

    原文链接:不修改模板的前提下修改VisualState中的某些值 - 超威蓝火 UWP里有一件非常令人不爽的事,大部分控件只提供了Normal状态下的Background,Foreground,Bor ...

  4. [wxgl] load image fail

    微信小游戏 let loader = new THREE.TextureLoader() let texture = loader.load('./images/bullet.png') 报错 参考 ...

  5. WebView 错误码整理

    在使用WebView中,我们不可避免的会接触到WebView加载失败的异常处理的需求,这时候,需要我们监听失败的方法也就是onReceivedError方法: public class CustomW ...

  6. Java 虚拟机的内存结构

    Java虚拟机运行时数据区 整个程序执行过程中,JVM会用一段空间来存储程序执行期间需要用到的数据和相关信息,这段空间一般被称作为Runtime Data Area(运行时数据区),也就是我们常说的J ...

  7. [源码]Delphi源码免杀之函数动态调用 实现免杀的下载者

    [免杀]Delphi源码免杀之函数动态调用 实现免杀的下载者 2013-12-30 23:44:21         来源:K8拉登哥哥's Blog   自己编译这份代码看看 过N多杀软  没什么技 ...

  8. mysql修改数据路径

    步凑: 1.关闭mysql服务 [root@localhost /]# service mysqld stop 2.移动mysql文件夹到自定义的目录 [root@localhost /]# mv / ...

  9. 爬虫--工具安装Jupyter anaconda

    anaconda https://www.anaconda.com/download http://docs.anaconda.com/anaconda/user-guide/getting-star ...

  10. 从零开始学 Web 之 BOM(四)client系列

    大家好,这里是「 从零开始学 Web 系列教程 」,并在下列地址同步更新...... github:https://github.com/Daotin/Web 微信公众号:Web前端之巅 博客园:ht ...