AjaxPro.NET实现Text@R_301_460@智能获取服务端数据功能
AjaxPro.NET是一个优秀的Ajax框架,在实际应用中只要添加其DLL引用并进行简单的配置,
即可以非常方便的在客户端直接调用服务端方法,实现验证目的.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AutoQueryText@R_301_460@.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>AutoQueryText@R_301_460@</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">AutoQueryText@R_301_460@</asp:Panel> <br /> <hr align="left" style="width: 473px" /> <br /> 输入查询字串: <asp:Text@R_301_460@ ID="txSearch" runat="server" Width="134px"></asp:Text@R_301_460@><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