ajax 笔记-- 写了一个不用刷新就能实现--用户名验证的例子
2006-10-29 18:05
1036 查看
现在用ajaxpro写了一个检测用户是否已经存在的例子
///判断用户是否已经存在
function userNameIsRepeat()
...{
var userName = document.getElementById("txtuserName").value;
if(userName == "")
...{
alert("请输入用户名");
document.getElementById("txtuserName").focus(); //调用焦点
return false;
}
else
...{
var userIsRepeat = Register.userNameIsRepeat(userName); //这个调用Register页aspx.cs里的,通过返回值进行的
if( userIsRepeat.value == true)
...{
alert("对不起此用户已经存在");
}
else
...{
alert("恭喜您,此用户还没有被注册");
}
}
}
在你的Register面当中加入<input type="text" id="txtusername"/><div id="userNameIsRepeat();">检测用户</div>
下面是Register.aspx.cs里的代码.
//在Register page_load里加入下面代码
protected void Page_Load(object sender, EventArgs e)
...{
AjaxPro.Utility.RegisterTypeForAjax(typeof(Register)); //跟具自己的写这个.
}
/**//// <summary>
/// 判断用记是不是已经存在了
/// </summary>
/// <param name="userName">用户名</param>
/// <returns></returns>
[AjaxPro.AjaxMethod]
public static bool userNameIsRepeat(string userName)
...{
string executeString = "select count(*) from users where userName = '" + userName + "'";
return TrueOrFalse(executeString);
}
/**//// <summary>
/// 返回是真(true)还是假(false)
/// </summary>
/// <param name="executeString">执行语句,或存储过程名称</param>
/// <returns></returns>
private static bool TrueOrFalse(string executeString)
...{
int count = int.Parse(GetCommand.ExecuteScalar(executeString)); //返回值
if (count >= 1)
...{
return true;
}
else
...{
return false;
}
}
///判断用户是否已经存在
function userNameIsRepeat()
...{
var userName = document.getElementById("txtuserName").value;
if(userName == "")
...{
alert("请输入用户名");
document.getElementById("txtuserName").focus(); //调用焦点
return false;
}
else
...{
var userIsRepeat = Register.userNameIsRepeat(userName); //这个调用Register页aspx.cs里的,通过返回值进行的
if( userIsRepeat.value == true)
...{
alert("对不起此用户已经存在");
}
else
...{
alert("恭喜您,此用户还没有被注册");
}
}
}
在你的Register面当中加入<input type="text" id="txtusername"/><div id="userNameIsRepeat();">检测用户</div>
下面是Register.aspx.cs里的代码.
//在Register page_load里加入下面代码
protected void Page_Load(object sender, EventArgs e)
...{
AjaxPro.Utility.RegisterTypeForAjax(typeof(Register)); //跟具自己的写这个.
}
/**//// <summary>
/// 判断用记是不是已经存在了
/// </summary>
/// <param name="userName">用户名</param>
/// <returns></returns>
[AjaxPro.AjaxMethod]
public static bool userNameIsRepeat(string userName)
...{
string executeString = "select count(*) from users where userName = '" + userName + "'";
return TrueOrFalse(executeString);
}
/**//// <summary>
/// 返回是真(true)还是假(false)
/// </summary>
/// <param name="executeString">执行语句,或存储过程名称</param>
/// <returns></returns>
private static bool TrueOrFalse(string executeString)
...{
int count = int.Parse(GetCommand.ExecuteScalar(executeString)); //返回值
if (count >= 1)
...{
return true;
}
else
...{
return false;
}
}
相关文章推荐
- ajax 笔记-- 写了一个不用刷新就能实现--用户名验证的例子
- 第一次用javascript写了一个不用刷新就能实现--用户名验证的例子
- 第一次用javascript写了一个不用刷新就能实现--用户名验证的例子
- 第一次用javascript写了一个不用刷新就能实现--用户名验证的例子
- Asp.net2005不用Ajax实现无刷新验证用户名、密码和中文验证码
- Asp.net2005不用Ajax实现无刷新验证用户名、密码和中文验证码
- Asp.net2005不用Ajax实现无刷新验证用户名、密码和中文验证码
- Asp.net2005不用Ajax实现无刷新验证用户名、密码和中文验证码
- Asp.net2005不用Ajax实现无刷新验证用户名、密码和中文验证码
- Asp.net2005不用Ajax实现无刷新验证用户名、密码和中文验证码
- Asp.net2005不用Ajax实现无刷新验证用户名、密码和中文验证码
- ajax 笔记--不用刷新实现数据的分页显示 2 (下)
- jsp+ajax实现无刷新,鼠标离开文本框即验证用户名
- Ajax实现无刷新验证用户名是否存在 (使用AjaxPro.2.dll)(当鼠标离开输入框时,即使判断用户名是否存在)
- MVC框架中 ajax实现无刷新用户名验证
- JQuery实现用户名无刷新验证的小例子
- ajax 笔记--不用刷新实现数据的分页显示 2 (下)
- ajax+javascript+php实现注册用户名无刷新验证
- jsp+ajax实现无刷新鼠标离开文本框即验证用户名
- 运用 Ajax技术 实现一个局部刷新显示的小例子