<%@ 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. Go Code Review Comments 译文(截止2018年7月27日)

    持续更新中- 原文最新链接 https://github.com/golang/go/wiki/CodeReviewComments/5a40ba36d388ff1b8b2dd4c1c3fe820b8 ...

  2. 背水一战 Windows 10 (68) - 控件(控件基类): UIElement - Pointer 相关事件, Tap 相关事件, Key 相关事件, Focus 相关事件

    [源码下载] 背水一战 Windows 10 (68) - 控件(控件基类): UIElement - Pointer 相关事件, Tap 相关事件, Key 相关事件, Focus 相关事件 作者: ...

  3. 项目Alpha冲刺(团队2/10)

    项目Alpha冲刺(团队2/10) 团队名称: 云打印 作业要求: 项目Alpha冲刺(团队) 作业目标: 完成项目Alpha版本 团队队员 队员学号 队员姓名 个人博客地址 备注 221600412 ...

  4. 收藏的blog

    https://www.cnblogs.com/xifengxiaoma/tag/vue/ https://www.cnblogs.com/xifengxiaoma/p/9400200.html

  5. 3.html基础标签:表格

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. HTML中的文本标签

    <span></span> 请使用 <span> 来组合行内元素,以便通过样式来格式化它们. 注释:span 没有固定的格式表现.当对它应用样式时,它才会产生视觉上 ...

  7. HTML5实现微信聊天气泡效果

    最近做一个HybridApp,前端有一个群聊的功能,于是就想模仿微信的聊天界面,先看效果图: HTML代码: <!DOCTYPE html> <html lang="en& ...

  8. php函数式编程

    // 函数式编程 $users = array( array('id' => 1, 'name' => 'abc1', 'age' => 29, '性别' => '男'), a ...

  9. web自动化测试---xpath方式定位页面元素

    在实际应用中,如果存在多个相同元素,包括属性相同时,一般会选用这种方式,当然如果定位属性唯一的话,也是可以使用的,不过这种方式没有像id,tag,name等容易理解,下面讲下xpath定位元素的方法 ...

  10. 关于resin的illegal utf8 encoding at (190)解决方式

    最近在项目开发中,出现了编码异常,内容如下:- illegal utf8 encoding at (190)com.caucho.jsp.JspParseException: illegal utf8 ...