Click here to Skip to main content
12,076,586 members (49,400 online)
Rate this:
 
Please Sign up or sign in to 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 14-Feb-13 6:43am
Edited 14-Feb-13 7:25am
v3
Comments
richcb 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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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 Big Grin | :-D

Best regards
Espen Harlinn
  Permalink  
v2
Comments
Marcus Kramer 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
Sergey Alexandrovich Kryukov 14-Feb-13 14:53pm
   
Thank you. :-)
By the way, I look at other comics at the side, did not find any interesting...
—SA
Espen Harlinn 14-Feb-13 15:14pm
   
Ohh, what about:
http://www.xkcd.com/303/
http://www.xkcd.com/138/
Sergey Alexandrovich Kryukov 14-Feb-13 15:21pm
   
Well... compiling... :-)
—SA
Espen Harlinn 14-Feb-13 15:34pm
   
But these days you'll have to have one heck of a codebase, and some very convoluted #includes before you'll notice - but I do remember waiting several hours for stuff to finish compiling - but that was in another millenium
Sergey Alexandrovich Kryukov 14-Feb-13 15:47pm
   
Not with Turbo/Borland Pascal :-) It was a great choice, in terms of build performance, too.
—SA
Espen Harlinn 14-Feb-13 15:52pm
   
It certainly was, and Delphi performed likewise.
Sergey Alexandrovich Kryukov 14-Feb-13 16:20pm
   
Delphi was an epic win, and still is. Too bad the language was not standardized. "ANSI Pascal" is nothing...
—SA
Espen Harlinn 14-Feb-13 16:22pm
   
I think Embarcadero is heading in the right direction, but repairing the damage done during the last years under Borland ownership will take time.
Sergey Alexandrovich Kryukov 14-Feb-13 16:27pm
   
Agree. It is very unfortunate that the line Algol -> Pascal -> Borland Pascal / Ada was considerably suppressed. This line is more clear, more academic and better based, etc...
—SA
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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//
            }
 
        }
    }
}
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web04 | 2.8.160208.1 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100