//声明XMLHttpRequest对象
var xmlHttp;//检测用户名是否存在
function CheckName(userName)
{
createXMLHTTP();//创建XMLHttpRequest对象
var url="DisposeEvent.aspx?userName="+userName+"&Event=Check";
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=checkUserName;
xmlHttp.send(null);
}function createXMLHTTP()
{
if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();//mozilla浏览器
}
else if(window.ActiveXObject)
{
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");//IE老版本
}
catch(e)
{}
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");//IE新版本
}
catch(e)
{}
if(!xmlHttp)
{
window.alert("不能创建XMLHttpRequest对象实例!");
return false;
}
}
}//执行检测用户名回调函数
function checkUserName()
{
if(xmlHttp.readyState==4)//判断对象状态
{
if(xmlHttp.status==200)//信息成功返回,开始处理信息
{
if(xmlHttp.responseText=="true")
{
document.getElementById("imgName").src="images/true.gif";
//让注册按钮失效
document.getElementById("btnReg").disabled=false;
}
else
{
document.getElementById("imgName").src="images/false.gif";
document.getElementById("btnReg").disabled=true;
}
}
}
}
var xmlHttp;//检测用户名是否存在
function CheckName(userName)
{
createXMLHTTP();//创建XMLHttpRequest对象
var url="DisposeEvent.aspx?userName="+userName+"&Event=Check";
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=checkUserName;
xmlHttp.send(null);
}function createXMLHTTP()
{
if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();//mozilla浏览器
}
else if(window.ActiveXObject)
{
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");//IE老版本
}
catch(e)
{}
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");//IE新版本
}
catch(e)
{}
if(!xmlHttp)
{
window.alert("不能创建XMLHttpRequest对象实例!");
return false;
}
}
}//执行检测用户名回调函数
function checkUserName()
{
if(xmlHttp.readyState==4)//判断对象状态
{
if(xmlHttp.status==200)//信息成功返回,开始处理信息
{
if(xmlHttp.responseText=="true")
{
document.getElementById("imgName").src="images/true.gif";
//让注册按钮失效
document.getElementById("btnReg").disabled=false;
}
else
{
document.getElementById("imgName").src="images/false.gif";
document.getElementById("btnReg").disabled=true;
}
}
}
}
解决方案 »
- .NET伪静态路径问题
- 大家 有vcastr播放器吗
- sql查询获取值问题
- postbackurl 不起作用
- 求助:panel的简单问题
- DataGrid中的按钮问题
- DateTime.Parse的问题。如何格式化DateTime类型数据。
- 大侠门,我想问下,哪有asp.net+C#与flash完美结合的教程和范例啊?我急用啊,大家有经验的也可以进来交流交流~
- 输入问题?
- 请教在DataGrid中弹出Confirm界面的问题
- 如何实现page1连接到page2时,自动提交page2的查询button?
- asp.net采用Oldb 向Excel文件中插入数据问题?在线等待!!!!!!!!!!!!
public partial class DisposeEvent : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
User user = new User();
//是否为执行CheckName方法
if (Request.QueryString["Event"].ToString() == "Check")
{
if (user.checkName(Request.QueryString["userName"].ToString()))
{
//当数据库中已存在此用户时输出为false,让其显示相应图标
Response.Write("false");
Response.End();
}
else
{
Response.Write("true");
Response.End();
}
}
}
}
public class User
{
public User()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
//检测用户名是否存在
string conStr = System.Configuration.ConfigurationSettings.AppSettings["HumanResources"];
public bool checkName(string userName)
{
SqlConnection userConnection = new SqlConnection(conStr);
SqlCommand userCommand = new SqlCommand("checkName", userConnection);
userCommand.CommandType = CommandType.StoredProcedure;//采用存储过程
userCommand.Parameters.Add("@userName", SqlDbType.VarChar, 50);//存储过程参数
userCommand.Parameters["@userName"].Value = userName;//给参数赋值
userCommand.Parameters.Add("@count",SqlDbType.Int);
userCommand.Parameters["@count"].Direction = ParameterDirection.Output;
userCommand.Connection.Open();//打开连接
userCommand.ExecuteScalar();//返回首行首列,如果存在的话返回1
int n =Convert.ToInt32( userCommand.Parameters["@count"].Value);
userCommand.Connection.Close();//关闭连接
if (n > 0)
{
return true;
}
else
{
return false;
}
}
}
==
这里我不是回过么
<input id="userName" type="text" onkeyup="CheckName(document.getElementById('userName').value);" />