Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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.
Posted
Updated 14-Feb-13 6:25am
v3
Comments
Richard C Bishop 14-Feb-13 11:45am    
This is not a question nor does it provide any information that anyone could deduce a helpful response to. Use the "Improve question" widget to elaborate on your issue and provide code that you have attempted already. Also, ask a specific question on where you are stuck.

 
Share this answer
 
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
 
Share this answer
 
v2
Comments
fjdiewornncalwe 14-Feb-13 13:15pm    
+5. Love the xkcd part.
Espen Harlinn 14-Feb-13 13:16pm    
Thank you, Marcus :-D
Sergey Alexandrovich Kryukov 14-Feb-13 14:20pm    
Too fine reply to this non-question. My 5. I would probably not answer, did not get enough patience. :-)
—SA
Sergey Alexandrovich Kryukov 14-Feb-13 14:24pm    
Oh, Exploits of a Mom is a fine example of SQL Injection. Another 5! Use parametrized queries!
If you don't mind, shall I use it next time I see a need to explain this exploit? :-)
—SA
Espen Harlinn 14-Feb-13 14:46pm    
Thanks Sergey, I don't mind at all - and I guess It's been posted in the lounge a couple of times too :-D
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]
XML
<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//
            }

        }
    }
}
 
Share this answer
 
v3
Comments
mn.sathish 14-Feb-13 12:08pm    
Hi Avik Ghosh. Thanks for your solution. But i want to check the user name availability while the user typing the username in the textbox. I don't want to check after submitting the form. Hope you will understand my problem.
Avik Ghosh22 14-Feb-13 12:22pm    
ok....wait..
Espen Harlinn 14-Feb-13 12:43pm    
1. Please edit your initial submission, don't add another one ...
2. Ever heard about SQL Injection: https://www.owasp.org/index.php/SQL_Injection

I've merged your three answers into one ...
Avik Ghosh22 14-Feb-13 12:55pm    
thank u sir...i know about sql injection ... earlier i had suffered a lot...

for a new comer its easy to understand so i give this solution..

thank u again for your advice .... and sorry for my poor English... :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900