如何在C#,ASP.Net中的TextBox中键入UserName时检查用户名可用性? [英] How to check the user name availability while typing the UserName in the TextBox in C#, ASP.Net?

查看:101
本文介绍了如何在C#,ASP.Net中的TextBox中键入UserName时检查用户名可用性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,

我是C#,ASP.Net的新手。现在我正在尝试创建新的帐户模块。在文本框字段中输入时,我不知道如何验证用户ID。



这意味着当用户输入用户名时。如果已存在此用户ID在数据库中,则消息显示此用户ID已存在。

解决方案

看看:

ASP.NET身份验证 [ ^ ]

ASP.NET授权 [ ^ ]

ASP.NET假冒 [ ^ ]



为此目的,还有.Net提供的用户界面组件:
登录类 [ ^ ]



如果你是ASP.Net的新手,这不是最好的起点,因为它可能会让你的系统开启各种各样的肮脏...... 。



查看对妈妈的利用 [ ^ ] - 这是一个很好的例子:-D



最好的问候

Espen Harlinn


使用页面方法验证用户名



http://blogs.microsoft .co.il / blogs / gilf / archive / 2008/10/04 / asp-net-ajax-pagemethods.aspx [ ^ ]


 protected void Button1_Click(object sender,EventArgs e)
{
using(SqlConnection con = new SqlConnection(----))
{
con.Open();
SqlCommand cmd = new SqlCommand(Select * FROM TEST WHERE ID =''+ TextBox1.Text +'',con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable DT = new DataTable();
da.Fill(DT);
con.Close();
if(DT.Rows.Count> 0)
{
Response.Write(ALREADY HAVE);
}
其他
{
//你的代码//
}

}
}





[更新]

其他明智的你可以使用自动完成文本框..



http://www.aspdotnet-suresh.com/2012 /08/using-jquery-autocomplete-with-aspnet.html [ ^ ]



使用ajax和c#在asp.net中自动完成文本框 [ ^ ] < br $> b $ b

[更新]

 <  正文 >  
< 表格 id = form1 runat = server >
< div >
< asp:TextBox ID = TextBox1 runat = server AutoPostBack = True

< span class =code-attribute> ontextchanged
= TextBox1_TextChanged > < / asp:TextBox >
< / div >
< / form >
< / body >



- ---------------------------



使用系统; 
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用System.Data.SqlClient;
使用System.Data;

public partial class Default2:System.Web.UI.Page
{
protected void Page_Load(object sender,EventArgs e)
{

}
protected void TextBox1_TextChanged(object sender,EventArgs e)
{
using(SqlConnection con = new SqlConnection(----))
{
con.Open();
SqlCommand cmd = new SqlCommand(Select * FROM TEST WHERE ID =''+ TextBox1.Text +'',con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable DT = new DataTable();
da.Fill(DT);
con.Close();
if(DT.Rows.Count> 0)
{
Response.Write(ALREADY HAVE);
}
其他
{
//你的代码//
}

}
}
}


Hi friends,
I''m new to C#, ASP.Net. Now i''am trying to work on create new account module. I don''t know how to validate the "User ID" while typing in the text box field.

It means when user enter the username.If already exist this userid in database then message show this userid already exist.

解决方案

Have a look at:
ASP.NET Authentication[^]
ASP.NET Authorization[^]
ASP.NET Impersonation[^]

There is also a user interface component that is provided with .Net for this purpose:
Login Class[^]

If you''re new to ASP.Net, this isn''t the best place to start, as it may open your system to all sorts of nastiness ...

Have a look at Exploits of a Mom[^] - it''s a nice example :-D

Best regards
Espen Harlinn


use page method for validation for username

http://blogs.microsoft.co.il/blogs/gilf/archive/2008/10/04/asp-net-ajax-pagemethods.aspx[^]


protected void Button1_Click(object sender, EventArgs e)
    {
         using (SqlConnection con = new SqlConnection("----"))
        {
            con.Open();
            SqlCommand cmd = new SqlCommand("Select * FROM TEST WHERE ID=''"+TextBox1.Text+"''", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable DT = new DataTable();
            da.Fill(DT);
            con.Close();
            if (DT.Rows.Count > 0)
            {
                Response.Write("ALREADY HAVE");
            }
            else
            {
                //YOUR CODE//
            }
            
        }
    }



[Update]
other wise u can use autocomplete textbox ..

http://www.aspdotnet-suresh.com/2012/08/using-jquery-autocomplete-with-aspnet.html[^]

Auto complete Textbox in asp.net using ajax and c#[^]

[Update]

<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"

            ontextchanged="TextBox1_TextChanged"></asp:TextBox>
    </div>
    </form>
</body>


----------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        using (SqlConnection con = new SqlConnection("----"))
        {
            con.Open();
            SqlCommand cmd = new SqlCommand("Select * FROM TEST WHERE ID=''" + TextBox1.Text + "''", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable DT = new DataTable();
            da.Fill(DT);
            con.Close();
            if (DT.Rows.Count > 0)
            {
                Response.Write("ALREADY HAVE");
            }
            else
            {
                //YOUR CODE//
            }

        }
    }
}


这篇关于如何在C#,ASP.Net中的TextBox中键入UserName时检查用户名可用性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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