首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

一个AJAX用户名验证有关问题!请大家帮忙指点下

2012-01-05 
一个AJAX用户名验证问题!请大家帮忙指点下!后台CS文件usingSystemusingSystem.DatausingSystem.Configur

一个AJAX用户名验证问题!请大家帮忙指点下!
后台   CS文件

using   System;
using   System.Data;
using   System.Configuration;
using   System.Collections;
using   System.Web;
using   System.Web.Security;
using   System.Web.UI;
using   System.Web.UI.WebControls;
using   System.Web.UI.WebControls.WebParts;
using   System.Web.UI.HtmlControls;


public   partial   class   RegisterPage   :   PageBase
{
        UserEntity   user   =   new   UserEntity();
       
        protected   void   Page_Load(object   sender,   EventArgs   e)
        {
                AjaxPro.Utility.RegisterTypeForAjax(typeof(RegisterPage));
              }
        [AjaxPro.AjaxMethod]
        public   string   select(string   username)
        {
                string   a   =   "已存在! ";
                string   b   =   "可以使用 ";
                //   string   username=   Request.QueryString[ "username "].ToString();
                string   sql   =   "select   *   from   BBS   where   bbsname= ' "   +   username   +   " ' ";
                DataSet   ds   =   DBAcess.GetDataSet(sql,   true);
                if   (ds.Tables[0].Rows.Count   >   0)
                {
                        return   a;
                }
                else
                        return   b;
        }
        [AjaxPro.AjaxMethod]
        public   string   pwd(string   p1,   string   p2)
        {
                string   a   =   "一致 ";
                string   b   =   "不一致 ";
                if   (p1   ==   p2)
                {
                        return   a;
                }
                else
                        return   b;
        }
}


前台文件   因为代码较长。我只贴出有关的部分。

<asp:Content   ID   = "reg "   ContentPlaceHolderID   = "Registerpage "   runat   = "server "   >

    <script   language= "javascript "   type= "text/javascript ">  


            function   textbox()
           
            {      
        var   username=document.getElementById( " <%#TextBox1.ClientID%> ").value;
              RegisterPage.select(username,getGroups_callback                   }               function   getGroups_callback(response)
          {
          document.getElementById( "tb ").value=response.value  
          //     var   dt=response.value;       alert(dt);  
                  }
          </script>

        <asp:Panel   ID= "Panel1 "   runat= "server "   Width= "269px "   >
        <%--个人用户--%>
        <table   > <tr> <td   > <%#Global.GetString( "RegType ")%> </td>
<td   style= "width:   158px "> <asp:RadioButtonList   ID= "SelectType "   runat= "server "   RepeatDirection= "Horizontal ">
        <asp:ListItem/> <asp:ListItem   />
        </asp:RadioButtonList> </td>
                <td   style= "width:   158px ">
                </td>
        </tr>
<tr> <td> <%#Global.GetString( "LabName ")%> </td> <td   style= "width:   158px "> <asp:TextBox   ID= "TextBox1 "   runat= "server "/> </td>
        <td   style= "width:   158px "> <input   id= "comit "   type= "button "   value= "检测用户名是否 "   onclick= "textbox() "/>
            <asp:TextBox   ID= "tb "   runat= "server "> </asp:TextBox>
        </td>
</tr>


现在运行页面后。点击按纽检测用户名老弹出一个对话框说
'document.getElementById() '为空或者不是对象


请大家指点下!谢谢了!

[解决办法]
查看源文件,看 <asp:TextBox ID= "tb " runat= "server "> </asp:TextBox> 这句生成的HTML中,ID是否还为 "tb ".
[解决办法]
var username=document.getElementById( " <%#TextBox1.ClientID%> ").value;
~~~~~~~~~~~~~~~~~~~~~~~~~~`
把这个改成 <%= TextBox1.ClientID %>
[解决办法]
在js中用alert抛出你想查看的值,看其中到底是什么东西,有什么没有取到
js的是比较难调试点
一步步跟下

热点排行