扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:朱先忠编译 来源:天极软件 2007年11月3日
关键字:
mainLoop = function() { val = escape(queryField.value); if(lastVal != val && searching == false){ var response = Main.GetSearchItems(val); showQueryDiv('smi', response.value); lastVal = val; } setTimeout('mainLoop()', 100); return true; }; |
using System; using System.Web.UI; using System.Web.UI.WebControls; namespace play{ /// <summary> /// AjaxLookup.cs /// </summary> public class AjaxLookup : TextBox{ private string scriptFile = ""; private string callBackFunction = ""; private string backgroundColor = "#EEE"; private string highlightColor = "#CCC"; private string font = "Verdana"; private string divPadding = "2px"; private string divBorder = "1px solid #CCC"; public string ScriptFile{ get { return scriptFile; } set { scriptFile = value; } } public string CallBackFunction{ get { return callBackFunction; } set { callBackFunction = value; } } public string BackgroundColor{ get { return backgroundColor; } set { backgroundColor = value; } } public string HighlightColor{ get { return highlightColor; } set { highlightColor = value; } } public string DivFont{ get { return font; } set { font = value; } } public string DivPadding{ get { return divPadding; } set { divPadding = value; } } public string DivBorder{ get { return divBorder; } set { divBorder = value; } } public AjaxLookup(){ this.Attributes.Add("autocomplete", "off"); } protected override void Render(HtmlTextWriter writer){ base.Render(writer); //绑定包含几乎所有逻辑的脚本 Page.RegisterStartupScript("LoadScript", "<script language='JavaScript' src='" + ScriptFile + "'>" + "</script>"); // 包括UI设置 string styles = String.Format( @"<script language='JavaScript'>var DIV_BG_COLOR = '{0}'; var DIV_HIGHLIGHT_COLOR = '{1}'; var DIV_FONT = '{2}'; var DIV_PADDING = '{3}'; var DIV_BORDER = '{4}'; </script>", BackgroundColor, HighlightColor, DivFont, DivPadding, DivBorder); Page.RegisterStartupScript("LookupStyles", styles); // 初始化回寄处理 Page.RegisterStartupScript("RegisterScript", "<script language='JavaScript'>" + "InitQueryCode('" + this.ClientID + "')</script>"); //设置正确的回调函数 Page.RegisterStartupScript("RegisterCallBack", @"<script language='JavaScript'> mainLoop = function() { val = escape(queryField.value); if(lastVal != val && searching == false){ var response = " + CallBackFunction + @"(val); showQueryDiv('smi', response.value); lastVal = val; } setTimeout('mainLoop()', 100); return true;}; </script>"); } } |
<Ajax:AjaxLookup Runat="Server" id="search" BackgroundColor="#EEE" DivBorder="1px solid #CCC" DivPadding="2px" DivFont="Arial" HighlightColor="#C30" CallBackFunction="Main.GetSearchItems" ScriptFile="lookup.js" /> |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者