用户注册页面 
“提交”控件 Button1的属性  ValidationGroup="cjy"  
如何在提交时检查 用户:TextBox1中所填写的 用户 可用

解决方案 »

  1.   

    客户端用js onclick 里面发请求查询.
    服务器端的话也差不多..
      

  2.   

    TextBox的onblur事件 写个js方法,验证用户名一般用ajax
      

  3.   

    检查用户名一般使用脚本
    document。from。控件名.value==null是检验是否为空
      

  4.   

    以sql server数据库为例:
    SqlConnection cn=new SqlConnection("连接字符串");
    SqlCommand cmd=nw SqlCommand("select count(*) from 用户表 where 用户名='"+TextBoxUserName.Text+"'",cn);
    if((int)cmd.ExecuteScalar()==0)
        //用户名可注册,进行注册.
    else
        //提示该用户名已被注册。
    cn.Close();
      

  5.   

        /// <summary>
        /// 判断用户名是否存在
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void txtUserName_TextChanged(object sender, EventArgs e)
        {
            try
            {
                //检查用户名是否存在
                DALUMUserManage.DTBUsersRow userInfo = BLLUMAddUser.GetUserByUserName(txtUserName.Text.Trim());
                //当前用户存在,则不可以用此用户名
                if (userInfo != null)
                {
                    ScriptManager.RegisterClientScriptBlock(this.upnAddUser, GetType(), "", "alert('" + HAConstants.MSG_USER_EXIST + "');", true);
                    txtUserName.Text = "";
                    txtUserName.Focus();
                    return;
                }
            }
            catch (CMMException cmmex)
            {
                //业务异常,画面内处理
                CMMLog.Error(cmmex.ToFullString());
                ScriptManager.RegisterClientScriptBlock(this.upnAddUser, GetType(), "ErrorMsg", "alert('" + cmmex.ToString() + "');", true);        }
            catch (Exception ex)
            {
                CMMLog.Debug(ex.ToString());
                //记录异常
                HAUtils.ErrorTeardown(Session, Response, ex);
            }
        }
      

  6.   

    就直接js吧!!!用onblur事件!
      

  7.   

    不行,……如果把“提交”控件 Button1的属性 ValidationGroup="cjy" 去掉即可检验用户是否可以,可是其他控件的检验 就失效了
     
      

  8.   

    onblur中通过ajax判断用户
    或onclicentclick判断用户
    ajax异步获取数据,查询用户数据   
    <script type="text/javascript">   
      var xmlHttp;   
      function createXMLHttpRequest()   
      {   
      if(window.ActiveXObject)   
      {   
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");   
      }   
      else if(window.XMLHttpRequest)   
      {   
      xmlHttp = new XMLHttpRequest();   
      }   
      }   
      function CheckUserName()   
      {   
      var us=document.getElementById("txtname").value;   
      if(us!="")   
      {   
      createXMLHttpRequest();   
      var url= "RegistValidate.ashx?username="+escape(document.getElementById("txtname").value);   
      xmlHttp.open("GET",url,true);   
      xmlHttp.onreadystatechange=ShowResult;   
      xmlHttp.send(null);   
      }   
      }   
      function ShowResult()   
      {   
      if(xmlHttp.readyState==4)   
      {   
      if(xmlHttp.status==200)   
      {   
      var s;   
      s=xmlHttp.responseText;   
      alert(s);   
      }   
      }   
      }   
    </script>   
     
      

  9.   

    直接服务器端验证吧,如果在客户端脚本里写,只可以限制一般用户。因为如果用AJAX的话,客户端是可以禁用JS的,所以可能导致数据库里有的用户名,也被注册