jQuery:SP.NET Autocomplete Textbox Using jQuery, JSON and AJAX
<%@ 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的更多相关文章
- 【jQuery】jquery-ui autocomplete智能提示
jQuery UI,简而言之,它是一个基于jQuery的前端UI框架.我们可以使用jQuery + jQuery UI非常简单方便地制作出界面美观.功能强大.跨浏览器兼容的前端html界面. Auto ...
- jQuery Validate 插件验证,,返回不同信息(json remote)自定义
问题 申请账号需要确认该账号是存在 jquery.validate.js中的remote Jquery Ajax获取后台返回的Json数据后,添加自定义校验 解题思路:输入的登陆信息远程验证是否该账号 ...
- struts2:使用JQuery、JSON和AJAX处理请求
目的 在struts2中使用JQuery.JSON.AJAX等技术处理用户请求,并返回结果.返回结果可以是以JSONObject的方式返回,也可以是以JSONArray方式返回结果. 实现 1. 创建 ...
- 弹窗中使用jquery ui的autocomplete自动完成插件无效果 实际是被遮挡了
在普通页面上使用jquery ui的autocomplete自动完成插件时正常显示提供选择的下拉框,但是放到弹窗中的时候就无法显示这个选择的下拉框,其它效果正常: 估计是被弹出窗遮挡了,网络搜索了jq ...
- jquery 自动完成 Autocomplete插件汇总
1. jQuery Autocomplete Mod jQuery Autcomplete插件.能够限制下拉菜单显示的结果数. 主页:http://www.pengoworks.com/worksho ...
- 不定义JQuery插件,不要说会JQuery 分类: JavaScript 2014-11-24 14:18 155人阅读 评论(0) 收藏
一:导言 有些WEB开发者,会引用一个JQuery类库,然后在网页上写一写$("#"),$("."),写了几年就对别人说非常熟悉JQuery.我曾经也是这样的人 ...
- [转]不定义JQuery插件,不要说会JQuery
一:导言 有些WEB开发者,会引用一个JQuery类库,然后在网页上写一写("#"),("."),写了几年就对别人说非常熟悉JQuery.我曾经也是这样的人,直 ...
- 不定义JQuery插件,不要说会JQuery
转自:http://www.cnblogs.com/xcj26/p/3345556.html 一:导言 有些WEB开发者,会引用一个JQuery类库,然后在网页上写一写$("#") ...
- aspx中的表单验证 jquery.validate.js 的使用 以及 jquery.validate相关扩展验证(Jquery表单提交验证插件)
这一期我们先讲在aspx中使用 jquery.validate插件进行表单的验证, 关于MVC中使用 validate我们在下一期中再讲 上面是效果,下面来说使用步骤 jQuery.Valid ...
随机推荐
- Android-Java-抽象类
定义抽象类,就一定会定义抽象方法,抽象方法没有方法体{},就证明抽象方法 是不运行的,抽象方法 是给子类继承覆盖运行的, 子类继承->抽象类 就必须覆盖抽象方法,否则编译都失败: 水果案例: 定 ...
- 关于ASP.NET MVC 中JsonResult返回的日期值问题
最近开始用MVC做项目,在使用 JsonResult返回数据的时候,日期被反射成了/Date 1233455这种格式,遍查网上都是在客户端使用JS来处理这个问题的,这样的话,就需要在每一个涉及到日期的 ...
- 开源播放器 ijkplayer (三) :ijkplayer支持 https 编译流程
主要是为了支持flv和m3u8,使用https播放视频的需求 ./init-android.sh ./init-android-openssl.sh // 增加https协议支持 cd android ...
- struts2框架学习笔记7:struts2标签
三大标签: 1.JSP:脚本,为了替代servlet,已过时 2.JSTL:标准标签库(core.format.sql.xml),还未淘汰的只有core库 3.Struts2标签库:由Struts2开 ...
- rocketmq搭建趟坑记
这个坑对小白来讲可能要趟很久才能过,我就是这样~~明明很简单的配置,搞了半天 我用的是rocketmq4.1.0,配置了jvm参数,都能正常启动,且能在线上运行demo,但是线下就是连不上 在conf ...
- MySQL的时间、日期型
MySQL的时间.日期型 MySQL中表示时间值的有DATE.时间类型为DATETIME.DATE.TIMESTAMP.TIME和YEAR.每个时间类型有一个有效值范围和一个"零" ...
- Testing - 软件测试知识梳理 - 测试用例
测试用例 是指对一项特定的软件产品进行测试任务的描述,体现测试方案.方法.技术和策略. 内容包括测试目标.测试环境.输入数据.测试步骤.预期结果.测试脚本等,并形成文档. 每个具体测试用例都将包括下列 ...
- 深度学习笔记(八)Focal Loss
论文:Focal Loss for Dense Object Detection 论文链接:https://arxiv.org/abs/1708.02002 一. 提出背景 object detect ...
- python函数练习——个人信息修改
修改个人信息程序 在一个文件里存多个人的个人信息,如以下 1.输入用户名密码,正确后登录系统 ,打印 1. 修改个人信息 2. 打印个人信息 3. 修改密码 2.每个选项写一个方法 3.登录时输错3次 ...
- [COI2007] Sabor
下面给出这道一脸不可做的题的鬼畜性质: 1)对于一个点来说,其归属状态是确定的:走不到.A党或B党 .(黑白格染色) 方便起见,将包含所有不可达的点的极小矩形向外扩展一圈,设为矩形M. 2)矩形M的最 ...