在asp.net中使用javascript保持自动完成功能

编程入门 行业动态 更新时间:2024-10-19 13:21:31
本文介绍了在asp中使用javascript保持自动完成功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是我的javascript:

This is my javascript :

<script src="js/jquery.js" type="text/javascript"></script> <link href="css/default.css" rel="stylesheet" type="text/css" media="screen" /> <link rel="stylesheet" href="code.jquery/ui/1.10.3/themes/smoothness/jquery-ui.css"> <script src="code.jquery/jquery-1.9.1.js"></script> <script src="code.jquery/ui/1.10.3/jquery-ui.js"></script> <script language="javascript" type="text/javascript"> $(function () { $('#<%=txtSearch.ClientID%>').autocomplete({ source: function (request, response) { $.ajax({ url: "Members1.aspx/GetName", data: "{ 'pre':'" + request.term + "'}", dataType: "json", type: "POST", contentType: "application/json; charset=utf-8", success: function (data) { response($.map(data.d, function (item) { return { value: item } })) }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert(textStatus); } }); } }); }); </script>

这是我的CS代码

this is my CS code

public partial class CP_News : System.Web.UI.Page { public string msg2; static string search = ""; SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString2"].ConnectionString); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["name"] == null) { Response.Redirect("Login.aspx"); } else { //BindRepeater(); allBindRepeater(); } } search = DropDownListSearch.SelectedItem.Text; } [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public static List<string> GetName(string pre) { List<string> allSearchName = new List<string>(); string key = search; using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = ConfigurationManager .ConnectionStrings["ConnectionString2"].ConnectionString; using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = conn; conn.Open(); if (key == "Mobile") { cmd.CommandText = "SELECT ContactNo FROM PersonalInformation where " + "ContactNo like N'" + pre + "%'"; using (SqlDataReader sdr = cmd.ExecuteReader()) { while (sdr.Read()) { allSearchName.Add(string.Format("{0}", sdr["ContactNo"])); } } } conn.Close(); } return allSearchName; } }

为文本框: < asp:TextBox ID =txtSearchrunat =server> 使用断点测试后,我发现在文本框中输入时控件不会在Getname函数内移动。 请求我知道mi错在哪里!!

for the textbox : <asp:TextBox ID="txtSearch" runat="server" > After testing using breakpoint, I found that the control doesn't move inside the "Getname" Function while typing in the textbox. Pleas let me know where m i wrong!!

推荐答案

( function (){

(' #<%= txtSearch.ClientID%>')。autocomplete( { source: function (request,response){ ('#<%=txtSearch.ClientID%>').autocomplete({ source: function (request, response) {

.ajax({ url: Members1.aspx / GetName, data: {'pre':' + request.term + '}, dataType: json, type: POST, contentType: 应用/ JSON; charset = utf-8,成功:功能(数据){ response( .ajax({ url: "Members1.aspx/GetName", data: "{ 'pre':'" + request.term + "'}", dataType: "json", type: "POST", contentType: "application/json; charset=utf-8", success: function (data) { response(

更多推荐

在asp.net中使用javascript保持自动完成功能

本文发布于:2023-10-31 16:10:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546601.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自动完成   功能   asp   net   javascript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!