C# ASP.NET中无刷新页面弹出对话框,并且页面跳转
ScriptManager.RegisterStartupScript(this, this.GetType(), "错误!", "alert('初始等级要小于要练的等级!');window.location='ItemsPage.aspx'", true);
.NET客户端的数据验证实例
asp.net代码块
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button7" runat="server" OnClientClick="javascript:return checkForm()" Text="提交" />
</form>
Javascript代码块
<script language="javascript" type="text/javascript">
function checkForm() {
if (document.form1.TextBox1.value == "") {
alert("怎么是空的!");
document.form1.TextBox1.focus();
return false;
}
var length = document.form1.TextBox1.value.length;
if (length < 6 || length > 10) {
alert("必须是6~10个字符内!");
return false;
}
}
</script>