南方网:ASP实例:简易ASP+注册系统

2020 年 8 月 21 日1520

南方网首页 > IT频道 > IT专题 > ASP教程

ASP实例:简易ASP+注册系统

2003-08-20 13:59

--------------------------------------------------------------

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQL" %>
<html>
<head><title>ASP+注册</title>
<link type="text/css" href="main.css">
<Script Language="C#" RunAt=Server>
void btnSubmit_Click(Object Src,EventArgs E)
{
if(Page.IsValid)
{
String strSQL;
strSQL="INSERT INTO tblUserInfo VALUES(@UserName,@PassWord,@Email)";

SQLConnection cnn=new SQLConnection("Server=niu;UID=sa;PWD=;DataBase=aspx");
SQLCommand cmm=new SQLCommand(strSQL,cnn);

cmm.Parameters.Add(new SQLParameter("@UserName",SQLDataType.VarChar,20));
cmm.Parameters["@UserName"].Value=txtName.Text;

cmm.Parameters.Add(new SQLParameter("@PassWord",SQLDataType.VarChar,20));
cmm.Parameters["@PassWord"].Value=txtName.Text;

cmm.Parameters.Add(new SQLParameter("@Email",SQLDataType.VarChar,60));
cmm.Parameters["@Email"].Value=txtName.Text;

cmm.ActiveConnection.Open();
try
{
cmm.Execute();
cmm.ActiveConnection.Close();
Page.Navigate("result.aspx");
}
catch
{
lblMsg.Style["color"]="red";
lblMsg.Text="插入数据出错";
}
}

}
</Script>
</head>
<body>
<h2>ASP+注册系统</h2>
<ASP:Label RunAt=Server/>
<form RunAt=Server>
<table bgcolor="#eeeeee" cellpadding="10">
<tr>
<td>姓名:</td>
<td>
<ASP:TextBox MaxLength="20" RunAt=Server/>
</td>
<td>
<ASP:RequiredFieldValidator
ControlToValidate="txtName"
Display="Dynamic"
InitalValue=""
ErrorMessage="*"
RunAt=Server>
</ASP:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>密码:</td>
<td>
<ASP:TextBox TextMode="PassWord" MaxLength="20" RunAt=Server/>
</td>
<td>
<ASP:RequiredFieldValidator
ControlToValidate="txtPassWord"
Display="Dynamic"
InitialValue=""
ErrorMessage="*"
RunAt=Server>
</ASP:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>确认密码:</td>
<td>
<ASP:TextBox TextMode="PassWord" MaxLength="20" RunAt=Server/>
</td>
<td>
<ASP:RequiredFieldValidator
ControlToValidate="txtRePassWord"
Display="Dynamic"
InitialValue=""
ErrorMessage="*"
RunAt=Server>
</ASP:RequiredFieldValidator>
<ASP:CompareValidator
ControlToValidate="txtRePassWord" ControlToCompare="txtPassWord"
Display="Dynamic"
ErrorMessage="密码确认错,请注意字母大小写!"
Runat=Server>
</ASP:CompareValidator>
</td>
</tr>
<tr>
<td>电子邮件:</td>
<td>
<ASP:TextBox MaxLength="60" RunAt=Server/>
</td>
<td>
<ASP:RequiredFieldValidator
ControlToValidate="txtEmail"
InitialValue=""
Display="Dynamic"
ErrorMessage="*"
RunAt=Server>
</ASP:RequiredFieldValidator>
<ASP:RegularExpressionValidator
ControlToValidate="txtEmail"
Display="Dynamic"
ErrorMessage="无效电子邮件地址!"
ValidationExpression="^[\w-]+@[\w-]+\.(com|net|org|edu|mil)$"
RunAt=Server>
</ASP:RegularExpressionValidator>
</td>
</tr>
<tr>
<td colspan="3">
<ASP:Button Text="提交" RunAt=Server/>
</td>
</tr>
</table>
</form>
</body>
</html>

编辑:付昱

作者: 新闻来源:南方网综合

【我要发言】【】【】

相关新闻:

· 摘要及底图

· 摘要及底图

· 摘要及底图

· 摘要及底图

· 关于ASP

0 0