还未点击注册 判断用户名是否存在

netajax 2010-01-20 09:45:09
还未点击注册 判断用户名是否存在

string userName = this.txtName.Text;
PersonalInfo bll = new PersonalInfo();
if (bll.Exists(userName))
{
this.lblInfo.Text = "用户名已经存在";
this.lblInfo.ForeColor = System.Drawing.Color.Red;
return;
}
else
{
this.lblInfo.Text = "恭喜您用户名可以使用";
this.lblInfo.ForeColor = System.Drawing.Color.Green;
}

除了这种,还有什么简单方法没有? 多谢了~!~!!~~!~!
...全文
798 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
Macy0606 2012-03-29
  • 打赏
  • 举报
回复
请问你这句 PersonalInfo bll = new PersonalInfo(); 的using是什么
itliyi 2010-01-20
  • 打赏
  • 举报
回复

...
<script>
var xmlHttp;

function createXmlRequest()
{
if(window.ActiveXObject)
{
var xmlHttps=["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp4.0",
"MSXML2.XMLHttp3.0","MSXML2.XMLHttp","Microsoft.XMLHTTP"];
try
{
for(var i=0;i<xmlHttps.length;i++)
{
var xmlHttp=new ActiveXObject(xmlHttps[i]);
return xmlHttp;
}
}
catch (error)
{
}

}
else
{
var xmlHttp=new XMLHttpRequest();
return xmlHttp;
}
throw new Error("失败");
}
function checkName(){
xmlHttp=createXmlRequest();
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.open("GET","Handler.ashx?user="+document.getElementById("txtUser").value+"",true);
xmlHttp.send(null);
}
function handleStateChange(){
if(xmlHttp.readyState==4){
if(xmlHttp.responseText=="Y")document.getElementById("divNameError").innerHTML="sorry 有人注册";
else document.getElementById("divNameError").innerHTML="";
}
}
</script>

<input type="text" id="txtUser" onblur="checkName();" /><div id="divNameError"></div>

Handler.ashx:

if(context.Request.QueryString["user"]!=null)
{
string userName=context.Request.QueryString["user"].ToString();
//检查
if(bll.Exists(userName))context.Response.Write("Y");
else context.Response.Write("N");
}
else context.Response.Write("N");context.Response.Flush();
netajax 2010-01-20
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 liushengmz 的回复:]
方法没问题,但是要感觉好点的话,用AJAX好点,不刷。。。。不闪。。。
[/Quote]

麻烦给我个例子 给我瞧瞧
liushengmz 2010-01-20
  • 打赏
  • 举报
回复
方法没问题,但是要感觉好点的话,用AJAX好点,不刷。。。。不闪。。。
zishanyan 2010-01-20
  • 打赏
  • 举报
回复
基本就是这样的思路
winform的话,可以放在textbox的textchange事件或者leave事件里

webform的话可以结合Ajax技术进行局部提交
iStringTheory 2010-01-20
  • 打赏
  • 举报
回复
用ajax在客户端查询,服务端返回查询结果,在用户输入用户名后就知道了是否可用。
OOOqqqOOO 2010-01-20
  • 打赏
  • 举报
回复
就是用微软的UpdatePanel就行了。

改变的时候立即检测。
mxc1225 2010-01-20
  • 打赏
  • 举报
回复
我只用过的是textchange事件!然后用ajax验证的!!
mohugomohu 2010-01-20
  • 打赏
  • 举报
回复
web的话用ajax
xray2005 2010-01-20
  • 打赏
  • 举报
回复
没有。你的方法没问题。如果要用户体验好点的话,可以采用AJAX来提升一下用户体验。
LoveLife_Go 2010-01-20
  • 打赏
  • 举报
回复
我没有
netajax 2010-01-20
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 itliyi 的回复:]
JScript code
...<script>var xmlHttp;function createXmlRequest()
{if(window.ActiveXObject)
{var xmlHttps=["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp4.0","MSXML2.XMLHttp3.0","MSXML2.XMLHttp","Microsoft.XMLHTTP"];try
{for(var i=0;i<xmlHttps.length;i++)
{var xmlHttp=new ActiveXObject(xmlHttps[i]);return xmlHttp;
}
}catch (error)
{
}

}else
{var xmlHttp=new XMLHttpRequest();return xmlHttp;
}thrownew Error("失败");
}function checkName(){
xmlHttp=createXmlRequest();
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.open("GET","Handler.ashx?user="+document.getElementById("txtUser").value+"",true);
xmlHttp.send(null);
}function handleStateChange(){if(xmlHttp.readyState==4){if(xmlHttp.responseText=="Y")document.getElementById("divNameError").innerHTML="sorry 有人注册";else document.getElementById("divNameError").innerHTML="";
}
}</script><input type="text" id="txtUser" onblur="checkName();"/><div id="divNameError"></div>
Handler.ashx:
C# codeif(context.Request.QueryString["user"]!=null)
{string userName=context.Request.QueryString["user"].ToString();//检查if(bll.Exists(userName))context.Response.Write("Y");else context.Response.Write("N");
}else context.Response.Write("N");context.Response.Flush();
[/Quote]


特别感谢下
netajax 2010-01-20
  • 打赏
  • 举报
回复
多谢多谢多谢

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧