Check userName availability


This article explain about code used for check the user name avilability for registering from data base. This code using Ajax concept for display of available message.

This code used for check the user name avilability for registering from data base. This code using Ajax concept for display of available message.


<td class="whiterow" >
<asp:UpdatePanel runat="server" ID="up1" >
<ContentTemplate>
<table>
<tr>
<td><asp:TextBox ID="txtUsername" AutoPostBack="true" OnTextChanged="Username_Changed" runat="server" CssClass="fontgnrl" ></asp:TextBox>
</td>
<td><div runat="server" id="UserAvailability"></div>
</td>
</tr>
</table>




</ContentTemplate>
</asp:UpdatePanel>



</td>
<tr>
<td height="25px" class="whiterow" align="center" colspan="3">
<asp:UpdatePanel runat="server" id="upSave" >
<ContentTemplate>
<asp:Button ID="btnProfileSave" runat="server" Text="Save" CssClass="btnsml" OnClick="btnProfileSave_Click" >
</asp:Button>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>

protected void Username_Changed(object sender, EventArgs e)
{
String UserName;
UserName = txtUsername.Text;
SqlParameter[] Params = new SqlParameter[1];

Params[0] = new SqlParameter("@UserName", SqlDbType.NVarChar );
Params[0].Value = UserName;

Int32 result =Convert.ToInt32(SqlDALHelper.ExecuteScalar("USP_UserNameAvailability", Params));

System.Threading.Thread.Sleep(2000);

//if (Membership.GetUser(txtUsername.Text) = 0)
if(result>0)
{
UserAvailability.InnerText = "Username taken, sorry.";
UserAvailability.Attributes.Add("class", "taken");
btnProfileSave.Enabled = false;
}
else
{
UserAvailability.InnerText = "Username available!";
UserAvailability.Attributes.Add("class", "available");
btnProfileSave.Enabled = true;
}
}




Comments

Guest Author: B Kumar23 Feb 2013

Mind Blowing!!!
Thank for posting such a nice Example



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: