asp.net user Registration Program

Source: Internet
Author: User

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" >
&LT;TR&GT;&LT;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>
&LT;TR&GT;&LT;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>
&LT;TR&GT;&LT;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>
&LT;TR&GT;&LT;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>
&LT;TR&GT;&LT;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>
&LT;TR&GT;&LT;TD colspan= "2" align= "center" >&nbsp;<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;
}
}

}
%》

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.