62,073
社区成员
发帖
与我相关
我的任务
分享
<script type="text/javascript" src="Scripts/jquery-1.4.1-vsdoc.js"></script>
<script type="text/javascript">
$(function () {
$(document).ready(function () {
$("#btt").click(function () {
$.ajax({
url: "Handler1.ashx",
type: "post",
datatype: "html",
data: {userName: $("#TextBox1").val()},
success: function (msg) {
if (msg != null) {
$("#div1").html("<font color='red'>" + msg + "</font>");
}
}
});
});
});
});
</script>
<body>
<form id="form1" runat="server">
<div id="div1">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<input type="button" value="点击我" id="btt" />
</div>
</form>
</body>
[code=C#]
public void ProcessRequest(HttpContext context)
{
string userName = context.Request["userName"];
if (userName != "HelloAccp")
{
string title = "用户名可以用";
context.Response.Write(title);
}
else
{
context.Response.Write("该用户名已经存在,不可以使用");
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using USTC;
using System.Data;
public partial class Admin_user_Registration : System.Web.UI.Page
{
DM dm = new DM();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDropDownList();
this.msg.Visible = false;
this.msg2.Visible = false;
}
}
protected void btnRegister_Click(object sender, EventArgs e)
{
string name = this.tbUserName.Text.Trim(); //用户名
string pwd = Common.MD5.ToMD5(this.tbUserPwd.Text.Trim()); //密码
string realname = this.tbRealName.Text.Trim(); //真实姓名
string inclass = string.Empty; //所在班级
if (this.ddlClass.SelectedItem.Text == "--请选择--")
{
this.msg2.Visible = true;
this.msg2.InnerText = "(*)请选择班级!";
}
else
{
inclass = this.ddlClass.SelectedItem.Text.Trim();
if (IsUserNameValid(name))
{
//用户名已经存在
this.msg.Visible = true;
this.msg.InnerText = "(*)该用户名已经存在!";
}
else
{
try
{
//用户名不存在,可以添加
string strSQL = "insert into tb_Users(RealName,InClass,Question,Answer) values('" + realname + "','" + inclass + "','" + name + "','" + pwd + "')";
dm.execsql(strSQL);
ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>alert('注册成功!');setTimeout('window.close();',2000);</script>");
}
catch (Exception)
{
}
}
}
}
/// <summary>
/// 绑定所在班级
/// </summary>
public void BindDropDownList()
{
string strSQL = "select * from tb_Class";
DataSet ds = dm.getsql(strSQL);
this.ddlClass.DataSource = ds;
this.ddlClass.DataTextField = "ClassName";
this.ddlClass.DataValueField = "ClassID";
this.ddlClass.DataBind();
this.ddlClass.Items.Insert(0,"--请选择--");
}
protected void btnReset_Click(object sender, EventArgs e)
{
this.tbUserName.Text = "";
this.tbUserPwd.Text = "";
this.tbRealName.Text = "";
this.ddlClass.SelectedIndex = 0;
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public bool IsUserNameValid(string name)
{
bool flag = false;
string strSQL = "select count(Question) as counter from tb_Users where Question='" + name.Trim() + "'";
DataSet ds = dm.getsql(strSQL);
if (ds.Tables[0].Rows[0]["counter"].ToString() != "0")
{
flag = true;
}
return flag;
}
}