ASP.Net:Ajax检查是否注册为用户? [英] ASP.Net: Ajax check for registration as a user?

查看:88
本文介绍了ASP.Net:Ajax检查是否注册为用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网站上有一个用户注册.

I have an user registration on my site.

我想让它看起来很酷,所以我的计划是,在保留文本框后,该文本框后面的绿色或红色符号告诉用户是否例如用户名未使用,电子邮件地址未使用,密码正确输入两次,依此类推.

I want to look it cool, so my plan is, that after a textbox is left, a green or red sign right behind the textbox tell the user if e.g. the username is unused, the email-adress is unused, the password is correct entered twice and so on.

是的,我知道验证控件,但是只有一堆函数,不是吗?例如.用于检查电子邮件地址是否未使用,我必须通过数据库进行检查,等等.

Yes, I know the validation controls, but there are only a bunch of functions, isn't it? E.g. for checking if the email-adress is unused I must check by database and so on...

有什么想法吗?

推荐答案

我会将整个内容包装在一个更新面板中,这是我经常做的事情...

I would wrap the whole thing in an update panel, this is something I do quite often...

<asp:scriptmanager runat="server" id="sm1" />
<asp:updatepanel runat="server" id="up1" updatemode="Conditional">
<contenttemplate>
    <asp:textbox runat="server" id="tbUsername" autopostback="true" ontextchanged="tbUsername_TextChanged" />
    <asp:customvalidator runat="server" text="Email already used" id="cusValEmail" />
    <asp:textbox runat="server" id="tbPassword"  />
</contenttemplate>
</asp:updatepanel>

以及后面的代码

protected void tbUsername_TextChanged(object sender, EventArgs e)
{
    //call DB etc and mark validator as needed
    cusValEmail.IsValid = false;
}

关键是将文本框自动回传设置为true并利用ontextchanged事件.

The key is setting the textbox autopostback to true and utilising the ontextchanged event.

这篇关于ASP.Net:Ajax检查是否注册为用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆