日期:2014-05-18 浏览次数:20389 次
<%@ Control Language="C#" %> <script runat="server"> protected void Page_PreRender(object sender, EventArgs e) { if (!IsPostBack) { var sc = this.Page.Form.Attributes["onsubmit"]; if (sc == null) sc = "return true;"; this.Page.Form.Attributes["onsubmit"] = string.Format("document.getElementById('{0}').value=document.activeElement.id;", this.HiddenField1.ClientID) + sc; } } public string ActiveClientID { get { return this.HiddenField1.Value; } } </script> <asp:HiddenField ID="HiddenField1" runat="server" />
<%@ Page Language="C#" %> <%@ Register Src="ActiveElementID.ascx" TagName="ActiveElementID" TagPrefix="uc2" %> <script runat="server"> protected void TextBox2_TextChanged(object sender, EventArgs e) { Regex reg = new Regex("^[1-9]([0-9]{3})$"); // Regex("^[\u4e00-\u9fa50-9a-zA-Z]+$"); if (reg.Match(TextBox2.Text).Success) { this.Message1.Visible = false; if (ActiveElementID1.ActiveClientID != string.Empty) Page.SetFocus(ActiveElementID1.ActiveClientID); } else { this.Message1.Visible = true; TextBox2.Focus(); } this.Message2.Visible = !Message1.Visible; } </script> <!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></title> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:TextBox ID="TextBox2" runat="server" AutoPostBack="true" OnTextChanged="TextBox2_TextChanged" /> <asp:Label runat="server" ID="Message1" Visible="false" Text="验证失败,只能输入4位数字" SkinID="Warning" /> <asp:Label runat="server" ID="Message2" Visible="false" Text="验证通过" SkinID="Pass" /> <br /> <asp:TextBox ID="TextBox3" runat="server" /> <br /> <asp:TextBox ID="TextBox4" runat="server" /> <br /> <asp:TextBox ID="TextBox5" runat="server" /> </ContentTemplate> </asp:UpdatePanel> <br /> <br /> <br /> <asp:Button ID="Button1" runat="server" T