Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello My dear Code Project Friends,

Display a POPUP Message while new registration, if the UserName Already Exists.
-------------------------------------------------------------------------

Am working on Asp.Net Project using (C#, Asp.Net, SqlServer 2005 Database)

I have created a Project. its almost finish

Presently I have created a Registration Page for adding New Users to Access my Project.

This Users will access the project with login, with their Username and Password.

Only Administrator has the permissions to create new user

So my requirement is................

I have 10 Textboxes in this registration page. and these are my fields..
FN, LN, UserName,Password,Department,Designation,EmailAddress,MobileNo,IssueDate,ExpiryDate.

so when i click on UserName and enter already existing username in USERNAME textbox...Automatically it should display a popup message.like (UserName Already Exists, Try another)


This message should be displayed while entering into UserName Textbox not after submit button click.

Please help.

Thanks in Advance.
Posted

I think this is what you are looking for;
Check username availability from database[^]
-or-

Better link : http://bit.ly/ZDo9Pj[^] :)

Good luck,
OI
 
Share this answer
 
v3
hii buddy

for this you have to write code on text_changed event of text box control..like this

C#
protected void TextBox1_TextChanged(object sender, EventArgs e)
    {

String str="select UserName from tablename where UserName='"+textbox1.text+"'";
Sqlconnection con=new sqlconnection();
Sqlcommand cmd=new sqlcomman(str, con)
con.open();

if(dr.read())
{
Response.Write("<script language="JavaScript">alert('UserName Already Exists, Try another')</script>");
}
else
{
Response.Write("<script language="JavaScript">alert('UserName Available, Please proceed')</script>");
}
con.close();
    }

if any error occurs comment below and be ensure for proper connection method from back end to front end
happy to help..
 
Share this answer
 
Comments
ZaneArellano 25-Feb-13 4:17am    
hi there,
i think it should be on the leave event of the textbox,
because when you put it on the textchanged event you will be having a popup every time it has a match in the database while typing and it's a little annoying for the user.
Plus every time the user enters a character in the textbox you will be querying from the database and it's a little bit strenuous on the server side
Sabyasachi Misra 12-Nov-13 1:06am    
yes yaar its coming error
Orcun Iyigun 25-Feb-13 5:00am    
Shubh: ya i think so...check on both events
Suk@nta 12-Nov-13 1:57am    
i agree with Zane that it should be after cursor leave the textbox area.Neither every character add or remove it will try to check in database and popup will be generate every match.This is not efficient one.
Shubh Agrahari 25-Feb-13 4:37am    
ya i think so...check on both events
Check this.Am using this and its working fine


http://www.dotnetspark.com/kb/Content.aspx?id=1278
 
Share this answer
 
Comments
Orcun Iyigun 12-Nov-13 2:03am    
You know this question is asked on February?
Sabyasachi Misra 12-Nov-13 8:04am    
but still if some body is going to check for answer he/she can find this solution
Orcun Iyigun 12-Nov-13 9:34am    
fair enough
First you need to add two update panel first will hold all of the content and with following properties
1.UpadteMode:conditional
2.childrenastriggers:false
3.Postback trigger controlid:"youbutonid"

now put another update panel inside of put youtextbox in which you are entering username.As shown below


XML
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
   </ajaxToolkit:ToolkitScriptManager>
<asp:UpdatePanel ChildrenAsTriggers="false" UpdateMode="Conditional" ID="UpdatePanel1"
       runat="server">
       <Triggers>
           <asp:PostBackTrigger ControlID="InsertDetailsButton" />
       </Triggers>
       <ContentTemplate>
 Put you main html here all that is going to postback on button click


<asp:UpdatePanel ID="UpdatePanel2" runat="server">
            <ContentTemplate>
                <asp:TextBox ID="YourTextBox" runat="server" class="text requiredField email" AutoPostBack="True" OnTextChanged="ClientIdTxtBox_TextChanged"></asp:TextBox>
                </ContentTemplate>
            </asp:UpdatePanel>
       </ContentTemplate>
   </asp:UpdatePanel>



Now ontextchanged call event handler

C#
protected void ClientIdTxtBox_TextChanged(object sender, EventArgs e)
       {
           try 
             //Put your logic here to check existing user name

               if ( name_Exist==true)
               {
                   ClientIdTxtBox.Text = "";
                   ScriptManager.RegisterStartupScript(this, GetType(), "AlertCode", "alert('User name already in use!');", true);
               }
           }
           catch (Exception ex)
           {

           }
       }


This will not postback whole of the page instead it will use partial postback.

Hope This helps!!!
 
Share this answer
 
Comments
Orcun Iyigun 12-Nov-13 2:03am    
You know this question is asked on February?
just on leave event of UserName check if the user exsits and if it does show windows notification message or message box
 
Share this answer
 
Comments
CHill60 12-Nov-13 14:44pm    
If you're going to answer an old question with 4 other solutions I think a little more detail in your response is called for.

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