ASP tutorial. NET User Registration Program
<%@ page language= "C #" autoeventwireup= "true" codefile= "Register.asp tutorial X.cs" inherits= "register"%>
<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd ">
<title> User Registration </title>
<script src= "Js/jquery.js" type= "Text/javascript Tutorial" ></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 the username already exists! ');
$ ("#btnregister"). Hide ();
} else {
$ ("#spanusercode"). HTML (' Congratulations to you the user name can be used! ');
$ ("#btnregister"). Show ();
}
})
return result;
}
</script>
<body>
<form id= "Form1" runat= "Server" >
<div style= "margin-left:100px;" >
<table width= "80%" cellpadding= "0" cellspacing= "0" >
<TR><TD colspan= "2" height= "align=" Center > Member Registration: <span style= "FONT-SIZE:12PX;" > Below <span style= "color:red;" >*</span> marked must be filled in </span></td></tr>
<TR><TD align= "Right" width= "40%" > member name:</td><td>
<asp:textbox id= "Txtusercode" runat= "Server" onblur= "checkuser" "maxlength=" width= "></asp:textbox" >
<%--<input id= "Txtusercode" runat= "Server" type= "text" Onblur= "CheckUser" () "Maxlength=" "width= >
<span style= "color:red;" >*</span>
<asp:requiredfieldvalidator id= "Requiredfieldvalidator3" runat= "Server"
Controltovalidate= "Txtusercode" errormessage= "member name can not be empty!" "></asp:requiredfieldvalidator>
<span id= "Spanusercode" ></span>
</td></tr>
<TR><TD align= "right > Password: </td><td><asp:textbox id=" txtpwd "textmode=" password "runat=" Server "width=" ></asp:textbox><span style= "color:red;" >*</span>
<asp:requiredfieldvalidator id= "Requiredfieldvalidator1" runat= "Server"
Controltovalidate= "txtpwd" errormessage= password cannot be empty! "></asp:requiredfieldvalidator>
</td></tr>
<TR><TD align= "Right" > Confirm password: </td><td><asp:textbox id= "TXTPWD1" runat= "Server" textmode= " Password "width=" ></asp:textbox><span style= "color:red;" >*</span>
<asp:comparevalidator id= "CompareValidator1" runat= "Server"
Controltocompare= "Txtpwd" controltovalidate= "Txtpwd1" errormessage= "two times password input inconsistent!" "></asp:comparevalidator>
</td></tr>
<TR><TD align= "Right" > real name: </td><td><asp:textbox id= "Txttruename" runat= "Server" width= "></asp:textbox>"
<span style= "color:red;" >*<asp:requiredfieldvalidator
Id= "Requiredfieldvalidator2" runat= "Server" controltovalidate= "Txttruename"
Errormessage= "name cannot be empty!" "></asp:requiredfieldvalidator>
</span></td></tr>
<TR><TD colspan= "2" align= "center" > <asp:button id= "Btnregister" onclientclick= "return" CheckUser (); "runat=" Server "text=" registration "
onclick= "Btnregister_click"/></td></tr>
</table>
</div>
</form>
</body>
Background:
<%
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 ("Registered success!") "," questionlist.aspx ");
}
%>
ASHX file: As a server and database tutorial interaction, JS pass over the user name
<%@ 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;
}
}
}
%》