zhzhqiu

检查用户名是否存在(验证过)

 <!--检查管理员是否重复-->
<script language="javascript" type="text/javascript">
function CheckUserName()
{

         var UserName= thisForm.txtUserName.value;
         if(UserName.length>0)
         {
            var tip = document.getElementById("lblUserNameTip");
              var objxml = new ActiveXObject("Microsoft.XMLHTTP");

            objxml.open("GET","/Include/Ajax/CheckUserName.aspx?UserName=" + UserName,false);

            objxml.send();

            var sResult=objxml.responseText;
            
            if(objxml.status=="200")
            {
                    switch(sResult)
                    {
                        case "true":
                            tip.innerHTML="";
                        break;
                        case "false":
                            tip.innerHTML="<font color=red>" + UserName + "已被占用!</font>";
                            thisForm.txtNewUserName.focus();
                        break;
                    }
            }

        }
}
 

</script>

 

验证文本框
 <asp:TextBox ID="txtUserName" runat="server" onBlur="CheckUserName()"></asp:TextBox>

 


cs代码

 


 protected void Page_Load(object sender, EventArgs e)
    {
        string sUserName = Request.QueryString["UserName"].Trim().ToString();

        OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings["SQLServerDAL"].ConnectionString);

        con.Open();
        string sql = "SELECT count(*) from T_User where UserName='" + sUserName + "'";
        OleDbDataAdapter da = new OleDbDataAdapter(sql, con);

        DataSet ds = new DataSet();
        da.Fill(ds);
        int userCount = int.Parse(ds.Tables[0].Rows[0][0].ToString());
        Response.Clear();
        if (userCount == 0)
        {
            Response.Write("true");

        }
        else
        {
            Response.Write("false");
        }
        Response.End(); 
    }

posted on 2009-02-27 22:22  网乐者  阅读(382)  评论(0编辑  收藏  举报

导航