您现在的位置: 军旅同心 >> 读书赏析 >> 学习园地 >> 电脑网络 >> 技术文章 >> 文章正文
简易ASP+注册系统
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005-9-10 13:27:26
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQL" %>
<html>
<head><title>ASP+注册</title>
<link rel="stylesheet" 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 align="center">ASP+注册系统</h2>
<ASP:Label ID="lblMsg" RunAt=Server/>
<form RunAt=Server>
  <table bgcolor="#eeeeee" cellpadding="10" align="center">
   <tr>
      <td>姓名:</td>
      <td>
        <ASP:TextBox ID="txtName" MaxLength="20" Class="mytext" RunAt=Server/>
      </td>
      <td>
        <ASP:RequiredFieldValidator ID="rfvName"
             ControlToValidate="txtName"
         Display="Dynamic"
         InitalValue=""
         ErrorMessage="*"
         RunAt=Server>
        </ASP:RequiredFieldValidator>
      </td>
    </tr>
    <tr>
      <td>密码:</td>
      <td>
    <ASP:TextBox ID="txtPassWord" TextMode="PassWord" MaxLength="20" Class="mytext" RunAt=Server/>
      </td>
      <td>
    <ASP:RequiredFieldValidator ID="rfvPassWord"
         ControlToValidate="txtPassWord"
         Display="Dynamic"
         InitialValue=""
         ErrorMessage="*"
         RunAt=Server>
    </ASP:RequiredFieldValidator>
      </td>
    </tr>
    <tr>
      <td>确认密码:</td>
      <td>
        <ASP:TextBox ID="txtRePassWord" TextMode="PassWord" MaxLength="20" Class="mytext" RunAt=Server/>
      </td>
      <td>
        <ASP:RequiredFieldValidator ID="rfvRePassWord"
         ControlToValidate="txtRePassWord"
         Display="Dynamic"
         InitialValue=""
         ErrorMessage="*"
         RunAt=Server>
    </ASP:RequiredFieldValidator>
    <ASP:CompareValidator ID="cvRePassWord"
         ControlToValidate="txtRePassWord" ControlToCompare="txtPassWord"
         Display="Dynamic"
         ErrorMessage="密码确认错,请注意字母大小写!"
         Runat=Server>
    </ASP:CompareValidator>
      </td>
    </tr>
    <tr>
      <td>电子邮件:</td>
      <td>
        <ASP:TextBox ID="txtEmail" MaxLength="60" Class="mytext" RunAt=Server/>
      </td>
      <td>
        <ASP:RequiredFieldValidator ID="rvfEmail"
         ControlToValidate="txtEmail"
         InitialValue=""
         Display="Dynamic"
         ErrorMessage="*"
         RunAt=Server>
    </ASP:RequiredFieldValidator>
    <ASP:RegularExpressionValidator ID="revEmail"
             ControlToValidate="txtEmail"
             Display="Dynamic"
             ErrorMessage="无效电子邮件地址!"
         ValidationExpression="^[w-]+@[w-]+.(com|net|org|edu|mil)$"
             RunAt=Server>
        </ASP:RegularExpressionValidator>
      </td>
    </tr>
    <tr>
      <td colspan="3" align="center">
        <ASP:Button ID="btnSubmit" OnClick="btnSubmit_Click" Text="提交" Class="mybtn" RunAt=Server/>      
      </td>
   </tr>
  </table>
</form>
</body>
</html>


 
免责声明:作品版权归所属媒体与作者所有!!本站刊载此文不代表同意其说法或描述,仅为提供更多信息。如果您认为我们侵犯了您的版权,请告知!本站立即删除。有异议请联系我们。
文章录入:烟灰缸    责任编辑:烟灰缸 
网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
| 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 | 网站公告 | 管理登录 |