看谁能解决?????????
问题是这样的,我尽量描述清楚,请大家看的仔细些,小弟先谢过了...
Register.aspx页面
处理页面:(已引入using System.Data.SqlClient)
DisposeEvent.asp.cs
User类中的检查用户是否存在的方法
数据库类DB.cs
我想实现的就是用ajax方法检查用户是否已注册,可是当我输入数据库中已存在的用户名时,还是提示“恭喜您,此用户可注册!”就是说在处理页面DisposeEvent.asp.cs中的返回值始终是false,进而造成了在调用回调函数时responseText始终是false,我设置断点跟踪,看到LoadUserData()方法中的Result始终是0,所以exist也就始终为false,即根本没执行数据库操作,但是我原先不用ajax就能用啊,怎么一到ajax就不行了呢?导致数据库操作没执行,可能是Request.QueryString["Name"].ToString()没接到值,但它是处理页面,且我只用.cs页面,不用设计页面,怎么判断啊?
Register.aspx页面
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
var xmlHttp=false;
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e2)
{
xml=false;
}
}
if(!xmlHttp)
{
xml=new XMLHttpRequest();
}
function checkUser(userName)
{
var url="DisposeEvent.aspx?Name="+userName;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=backInfo;
xmlHttp.send(null);
}
function backInfo()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
alert("false");
if(xmlHttp.responseText=="true")
{
document.getElementById('message').innerHTML="对不起,此用户已存在!";
}
else
{
document.getElementById('message').innerHTML="恭喜您,此用户可注册!";
}
}
}
}
</script>
</head>
<table style="width: 500px; height: 164px">
<tr>
<td style="width: 80px">
用户名:</td>
<td style="width: 100px">
<input id="userName" type="text" onchange="checkUser(document.getElementById('userName').value)"/></td>
<td style="width: 100px">
<div id="message"></div>
</td>
</tr>
<tr>
<td style="width: 80px">
密码:</td>
<td style="width: 100px">
<input id="userPwd" type="text" /></td>
<td style="width: 100px">
</td>
</tr>
<tr>
<td colspan="3">
<input id="RegBtn" type="button" value="注册" /></td>
</tr>
</table>
处理页面:(已引入using System.Data.SqlClient)
DisposeEvent.asp.cs
public partial class DisposeEvent : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
User user = new User();
if (user.LoadUserData(Request.QueryString["Name"].ToString()))
{
Response.Write("true");
Response.End();
}
else
{
Response.Write("false");
Response.End();
}
}
}
User类中的检查用户是否存在的方法
public bool LoadUserData(string userName)
{
int Result = 0;
bool exist = false;
SqlConnection con = DB.createDB();
SqlParameter pUserName = new SqlParameter("@UserName", SqlDbType.VarChar, 100);
pUserName.Value = userName;
string SqlText = string.Format("select count(*) from Users where UserName={0}", pUserName);
SqlCommand sqlcmd = new SqlCommand(SqlText,con);
sqlcmd.Parameters.Add(pUserName);
try
{
con.Open();
Result = Convert.ToInt32(sqlcmd.ExecuteScalar());
if (Result > 0)
{
exist = true;
}
}
catch(SqlException ex)
{
throw new Exception(ex.Message,ex);
}
finally
{
con.Close();
}
return exist;
}
数据库类DB.cs
public class DB
{
public DB()
{
}
public static SqlConnection createDB()
{
string sqlcon = "server=(local);database=practice;uid=sa;pwd=;";
SqlConnection con = new SqlConnection(sqlcon);
return con;
}
}
我想实现的就是用ajax方法检查用户是否已注册,可是当我输入数据库中已存在的用户名时,还是提示“恭喜您,此用户可注册!”就是说在处理页面DisposeEvent.asp.cs中的返回值始终是false,进而造成了在调用回调函数时responseText始终是false,我设置断点跟踪,看到LoadUserData()方法中的Result始终是0,所以exist也就始终为false,即根本没执行数据库操作,但是我原先不用ajax就能用啊,怎么一到ajax就不行了呢?导致数据库操作没执行,可能是Request.QueryString["Name"].ToString()没接到值,但它是处理页面,且我只用.cs页面,不用设计页面,怎么判断啊?
...全文
相关推荐
1_?????????_1H-????_arduino_zip_
arduino lecture material
数学新建考试题.pdf
数学新建考试题.pdf
基于java的-114-jspm个人所得税服务系统-源码.zip
基于java的-114-jspm个人所得税服务系统-源码.zip
eclipse develop hadoop chmod :Cannot run program "chmod": CreateProcess error=2, ?????????-附件资源
eclipse develop hadoop chmod :Cannot run program "chmod": CreateProcess error=2, ?????????-附件资源
51?????_?????????_12864LCD_
拉卡拉 拆机显示lcd 12864的lcd驱动,及针脚定义。


