请问如何使用ajax.dll组件 判断用户名是否存在?
下面是我的ajax的方法,不知可否实现,返回count>0提示用户名存在。问题是如何用javascrip判断这个count的值。[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
        public  int GetCount(string customerID)
        {
            SqlConnection conn = new SqlConnection("server=localhost;database=test;uid=sa;pwd=sasa");
            SqlCommand cmd = new SqlCommand("select count(*) from Customer where CustomerID=@CustomerID", conn);
            SqlParameter p1 = new SqlParameter("@CutomerID", SqlDbType.NVarChar, 100);
            cmd.Parameters.Add(p1);
            conn.Open();
            int count = Convert.ToInt32(cmd.ExecuteScalar());
            conn.Close();
            return count;
        }

解决方案 »

  1.   

    然后呢,在<script> </script>的代码如何写呀,
      

  2.   

    要用xmlhttp来获取返回的值如果你用ajaxpro的话,那直接到前台调用就行了
      

  3.   

    前台写个调用函数:
    函数体调用GetCount(customerID,GetCount_CallBack);//GetCount_CallBack()为回调函数,在GetCount_CallBack中用Response.value获取你的返回值。
      

  4.   

    我的一个例子:
     后台方法返回的是bool类型,不过你照着做就可以了
    function UserAdd()
           {
            var User=document.getElementById("user").value;
            if(Default.IsExist(User))    //调用后台方法,如果返回true则表示该联系人已经存在
            {
             alert("该联系人已经存在!");
             return false;
            }
            else
            {
             //没注册则...你自己的代码
             }
      

  5.   

    后台cs:      判断用户是否存在
     [AjaxPro.AjaxMethod]
      public bool IsExist(string linkman)
      {
        return MessageContext.Cuurent.IsExist(linkman);
      }
      

  6.   

    其中判断用户是否存在的方法和你的一样,如果count=0则返回false,不存在改用户,如果count〉1则返回true,该用户已经存在
      

  7.   

    zdyguilong(Keep Walking!) ( ) 信誉:100    Blog  2006-12-18 17:25:27  得分: 0  
     
     
       关注,一直想得到这个效果的源代码
      
     
    那你把这个改成bool型就可以了
            public  int GetCount(string customerID)
            {
                SqlConnection conn = new SqlConnection("server=localhost;database=test;uid=sa;pwd=sasa");
                SqlCommand cmd = new SqlCommand("select count(*) from Customer where CustomerID=@CustomerID", conn);
                SqlParameter p1 = new SqlParameter("@CutomerID", SqlDbType.NVarChar, 100);
                cmd.Parameters.Add(p1);
                conn.Open();
                int count = Convert.ToInt32(cmd.ExecuteScalar());
                conn.Close();
                return count;
            }
      

  8.   

    function testAjax()
      {
       var first=document.getElementById("txtfirst");
       AjaxMethod.GetCount(first.value,callback_GetCount);
      }
      function callback_GetCount(res)
      {
      
       var obj=document.getElementById("txtsecond");   
       obj.value=res.value;    
      }
    我在button onclick事件中调用上面的函数,我输入一个用户名在另一个textbox中应该显示0或1,可是得到的却是null,怎么回事???
      

  9.   

    照着我的做就可以了,搞那么复杂干什么,真是想不懂你们这些人
     protected void Page_Load(object sender, EventArgs e)
      {    
        AjaxPro.Utility.RegisterTypeForAjax(typeof(Default));//把这个page注册一下
      }
     [AjaxPro.AjaxMethod]
      public bool IsExist(string linkman)
      {
        return MessageContext.Cuurent.IsExist(linkman);
      }
    前台调用
     alert(Default.IsExist(document.getElementById("USER").value));
     结果返回true或者false
      

  10.   

    http://blog.sina.com.cn/u/3e4c565b010005aq
      

  11.   

    ustbwuyi() 挺强的
    曾经帮助过我,可当时就是没搞定
      

  12.   

    呵呵,没搞定,我注册了呀,你那个不访问数据库ustbwuyi
      

  13.   

    说不明白,看代码吧:
    <script language="javascript" type="text/javascript">
    function Exist()
    {
    var code = document.all("tbCode").value;
    var result=CompanyManage_Login_Default.GetExist(code).value;
    if(result<1)
    {
    alert("不存在此用户!");
    document.all("tbCode").focus();
    return false;
    }
    }    
    </script>
    ========================================
    [Ajax.AjaxMethod()]
    public int GetExist(int iCode)
    {
    Company_Login clMain = new Company_Login();
    return clMain.Exist(iCode);
    }