TextBox输入值自动获取后台匹配值

前端之家收集整理的这篇文章主要介绍了TextBox输入值自动获取后台匹配值前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

AjaxPro.NET实现TextBox智能获取服务端数据功能
AjaxPro.NET是一个优秀的Ajax框架,在实际应用中只要添加其DLL引用并进行简单的配置,
即可以非常方便的在客户端直接调用服务端方法,实现验证目的.

效果显示:

前台调用代码:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="AutoQueryTextBox.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>AutoQueryTextBox</title>
    <script language="javascript" src="lookup.js"></script>
	<script language="jscript">
		mainLoop = function () {
		    val = escape(queryField.value);
		    if (lastVal != val) {
		        var response = _Default.GetSearchItems(val);
		        showQueryDiv(response.value);
		        lastVal = val;
		    }
		    setTimeout('mainLoop()',100);
		    return true;
		}        
    </script>
</head>
<body >
    <form id="form1" runat="server">
    <div>
        <asp:Panel ID="Panel1" runat="server" BackColor="#C0C0FF" Font-Bold="True" Font-Overline="False" Font-Size="XX-Large" Height="37px" Width="475px">AutoQueryTextBox</asp:Panel>
        <br />
        <hr align="left" style="width: 473px" />
        <br />
        输入查询字串: <asp:TextBox ID="txSearch" runat="server" Width="134px"></asp:TextBox><br />
        <br />
    </div>
    <script language="jscript">
        InitQueryCode("" + '<%= txSearch.ClientID %>' + "");
    </script>    
    </form>
</body>
</html>


后台方法调用:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using AjaxPro;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender,EventArgs e)
    {       
       Utility.RegisterTypeForAjax(typeof(_Default));
    }

   [AjaxMethod()]// or [AjaxPro.AjaxMethod] 
   public ArrayList GetSearchItems( string strQuery )
   {
      //生成数据源
      ArrayList items = new ArrayList();
      items.Add("Codefans.net");
      items.Add("code");
      items.Add("cso");
	  items.Add("abcdefg");
	  items.Add("cso");
	  items.Add("ajax");
	  items.Add("236");
	  items.Add("qzone");
      items.Add("123");
      items.Add("5678.com");
      items.Add("www.baidu.com");
      items.Add("aspx.net"); 

      //筛选数据
      ArrayList selectItems = new ArrayList();
      foreach( string str in items )
      {
         if (str.ToUpper().IndexOf(strQuery.ToUpper()) == 0)
         {
            selectItems.Add(str);
         }
      }
      return selectItems;
   }  
}

来源于:http://www.codefans.net
案例下载地址1:http://download.csdn.net/detail/lovegonghui/9177325

案例下载地址2:http://down.51cto.com/data/2105139

原文链接:https://www.f2er.com/ajax/162844.html

猜你在找的Ajax相关文章