<head runat= "server ">
<title> 无标题页 </title>
<script language= "javascript ">
function check()
{
var email = document.getElementById( 'TextBox1 ');
var pwd = document.getElementById( 'TextBox2 ');
if (email.value== " " || pwd.value== " ")
{
alert( "请填写完整内容 ");
return false;
}
else
{
var mailStr = /((\w)+)@((\w)+).[cc|com|net|org|tv|cn]/ig;
if (!mailStr.exec(email.value))
{
alert( 'Email地址书写不正确!\n请您重新输入! ');
email.value = ' ';
email.focus();
return false;
}
}
}
</script>
</head>
<body>
<form id= "form1 " runat= "server ">
<div>
<asp:TextBox ID= "TextBox1 " runat= "server "> </asp:TextBox>
<asp:TextBox ID= "TextBox2 " runat= "server "> </asp:TextBox>
<asp:Button ID= "Button1 " runat= "server " Text= "Button " OnClientClick= "check() " OnClick= "Button1_Click1 " /> </div>
</form>
</body>
上面这段是ASPX文件主体,页面上有两个TextBox 和一个Button ,Button 有两个事件,一个客户端事件,一个写在后配代码CS文件中,如下