<%@ 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. linux(centos7)安装docker

    1.检查内核版本,必须是3.10及以上 uname ‐r 2.安装docker yum install docker 3.输入y确认安装 4.启动docker [root@localhost ~]# ...

  2. PHP注释

    PHP支持C.C++和 Shell 脚本风格的注释. 单行注释 两个反斜线组成的单行注释 // 注释内容 一个井号组成的单行注释 # 注释内容 说明:PHP单行注释几乎用的都是//,很少使用#来注释内 ...

  3. [视频]K8飞刀 S2-020 exploit getshell 动画教程

    [视频]K8飞刀 S2-020 exploit getshell 动画教程 链接:https://pan.baidu.com/s/1G5x7Dcu6pzHz6ZfSCDDmKA 提取码:05kw

  4. 异步与并行~CancellationTokenSource对线程的作用

    返回目录 说起CancellationTokenSource我们应该不会陌生,对于Thread,Task来说,我们启动一个线程去做一些事,如果希望它在某个阶段去被动的停止,可以使用这个Cancella ...

  5. Spring Boot + Spring Cloud 实现权限管理系统 后端篇(二十三):配置中心(Config、Bus)

    在线演示 演示地址:http://139.196.87.48:9002/kitty 用户名:admin 密码:admin 技术背景 如今微服务架构盛行,在分布式系统中,项目日益庞大,子项目日益增多,每 ...

  6. paperpass

    推荐大家一个靠谱的论文检测平台.重复的部分有详细出处以及具体修改意见,能直接在文章上做修改,全部改完一键下载就搞定了.怕麻烦的话,还能用它自带的降重功能.哦对了,他们现在正在做毕业季活动, 赠送很多免 ...

  7. process_begin: CreateProcess(NULL,......) make (e=87): 参数错误。

    在编译 trinity-android 的过程中,总是报 process_begin: CreateProcess(NULL,......) make (e=87): 参数错误 原因是.MK文件中包含 ...

  8. 获取多个checkbox的选中值

    我在这个div中添加了多个input. 拼接一下呢.最老的方法. jquery获取值: var strSel=""; $("[name='jbbm']:checked&q ...

  9. JavaWeb学习(一)———JavaWeb入门

    一.基本概念 1.1.WEB开发的相关知识 WEB,在英语中web即表示网页的意思,它用于表示Internet主机上供外界访问的资源. Internet上供外界访问的Web资源分为: 静态web资源( ...

  10. OpenCV设置保存图像压缩率

    OpenCV写入静态图片时,imwrite函数第三个参数可以设置压缩率,默认值为95. cv::Mat inImage= cv::imread("lena.jpg"); vecto ...