程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> ASP編程 >> ASP技巧 >> 簡易ASP+注冊系統

簡易ASP+注冊系統

編輯:ASP技巧

<%@ 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>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved