【www.gdgbn.com--安卓教程】
asp教程.net用户注册程序
<%@ page language="c#" autoeventwireup="true" codefile="register.asp教程x.cs" inherits="register" %>
<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>
后台:
<%
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;
}
}}
%》