webusercontrol1.ascx

来自「另一新版ajax组件」· ASCX 代码 · 共 51 行

ASCX
51
字号
<%@ Control Language="c#" Inherits="System.Web.UI.UserControl" ClassName="WebUserControl1" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<script language="C#" runat="server">

public System.Reflection.MethodInfo method = null;

private void Page_Load(object sender, System.EventArgs e)
{
	AjaxPro.Utility.RegisterTypeForAjax(typeof(WebUserControl1), this.Page);
}

[AjaxPro.AjaxMethod]
public int GetLength(string s)
{
	return s.Length;
}

</script>

<script type="text/javascript">

var textLen = Class.create();

textLen.prototype = {
	initialize: function(ele) {
		this.timer = null;
		this.ele = ele;
		this.display = document.getElementById(this.ele.id + "_display");
		addEvent(this.ele, "keyup", this.dosearch.bind(this));
	},
	dosearch: function() {
		if(this.timer != null) clearTimeout(this.timer);
		this.timer = setTimeout(this.dosearch_next.bind(this), 100);
	},
	dosearch_next: function() {
		ASP.WebUserControl1.GetLength(this.ele.value, this.ondata.bind(this));
	},
	ondata: function(res) {
		this.display.innerHTML = res.value;
	}
};

function init() {
	var x = new textLen(document.getElementById("<%=ClientID%>"));
	x.ele.focus();
}

addEvent(window, "load", init);

</script>
<input type="text" id="<%=ClientID%>"/>
<div>Length of the string: <span id="<%=ClientID%>_display">0</span></div>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?