asp.net使用者註冊程式

來源:互聯網
上載者:User

asp教程.net使用者註冊程式
<%@ page language="c#" autoeventwireup="true" codefile="register.asp教程x.cs" inherits="register" %>

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">

<html xmlns="http://www.111cn.net/1999/xhtml">
<head runat="server">
  <title>使用者註冊</title>
 

<script src="js/jquery.js" type="text/javascript教程"></script>
  <script>
  function checkuser() {
   
  var usercode = $("#txtusercode").val();
  $.get("register.ashx", { usercode: usercode }, function(data) {

  var msg = eval(data);
  if (msg == 1) {
  $("#spanusercode").html('sorry該使用者名稱已經存在!');
  $("#btnregister").hide();
   
  } else {
  $("#spanusercode").html('恭喜您該使用者名稱可以使用!');
   
  $("#btnregister").show();
  }
  })
  return result;
  }
</script>

</head>
<body>
 

<form id="form1" runat="server">
  <div style=" margin-left:100px;">
  <table width="80%" cellpadding="0" cellspacing="0">
  <tr><td colspan="2" height="30" align="center">會員註冊:<span style=" font-size:12px;">以下<span style=" color:red;">*</span>標記的為必填項</span></td></tr>
  <tr><td align="right" width="40%">會員名:</td><td>
  <asp:textbox id="txtusercode" runat="server" onblur="checkuser()" maxlength="30" width="200"></asp:textbox>
  <%-- <input id="txtusercode" runat="server" type="text" onblur="checkuser()" maxlength="30" width="200"/>--%>
  <span style=" color:red;">*</span>
  <asp:requiredfieldvalidator id="requiredfieldvalidator3" runat="server" 
  controltovalidate="txtusercode" errormessage="會員名稱不可為空!"></asp:requiredfieldvalidator>
  <span id="spanusercode"></span>
   
  </td></tr>
  <tr><td align="right">密碼:</td><td><asp:textbox id="txtpwd" textmode="password" runat="server" width="200"></asp:textbox><span style=" color:red;">*</span>
  <asp:requiredfieldvalidator id="requiredfieldvalidator1" runat="server" 
  controltovalidate="txtpwd" errormessage="密碼不可為空!"></asp:requiredfieldvalidator>
  </td></tr>
  <tr><td align="right">確認密碼:</td><td><asp:textbox id="txtpwd1" runat="server" textmode="password" width="200"></asp:textbox><span style=" color:red;">*</span>
  <asp:comparevalidator id="comparevalidator1" runat="server" 
  controltocompare="txtpwd" controltovalidate="txtpwd1" errormessage="兩次密碼輸入不一致!"></asp:comparevalidator>
  </td></tr>
  <tr><td align="right">真實姓名:</td><td><asp:textbox id="txttruename" runat="server" width="200"></asp:textbox>
  <span style=" color:red;">*<asp:requiredfieldvalidator 
  id="requiredfieldvalidator2" runat="server" controltovalidate="txttruename" 
  errormessage="姓名不可為空!"></asp:requiredfieldvalidator>
  </span></td></tr>
  <tr><td colspan="2" align="center">&nbsp;<asp:button id="btnregister" onclientclick="return checkuser();" runat="server" text=" 注 冊 " 
  onclick="btnregister_click" /></td></tr>
  </table>
  </div>
  </form>
</body>
</html>

後台:

<%
protected void btnregister_click(object sender, eventargs e)
  {
  string usercode = txtusercode.text.trim();
  string userpwd = common.getmd5(txtpwd.text.trim());
  string username = txttruename.text;
  string sql = string.empty;

  stringbuilder sb = new stringbuilder();
  sb.append("insert into nw_admin(nw_usercode,nw_pwd,nw_username,nw_class)");
  sb.append("values('" + usercode + "','" + userpwd + "','" + username + "',0)");
  int temp = sqlhelp.executesql(sb.tostring());
  if (temp > 0)
  common.jsredirect("註冊成功!", "questionlist.aspx");
  }
 %>
//ashx檔案:作為伺服器與資料庫教程互動,js傳過來的使用者名稱
<%@ webhandler language="c#" class="register" %>
<%
using system;
using system.web;

public class register : ihttphandler {
   
  public void processrequest (httpcontext context) {
  context.response.contenttype = "text/plain";
  if (!string.isnullorempty(context.request["usercode"]))
  {
  string usercode = context.request["usercode"].tostring();
  string sql = "select count(1) from nw_admin where nw_usercode='"+usercode.trim()+"'";
  bool result = sqlhelp.exists(sql);
  if (result)
  context.response.write(1);
  else
  context.response.write(0);
  }
  }
 
  public bool isreusable {
  get {
  return false;
  }
  }

}
%》

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.