Home > AJAX, ASP.Net > How to Check UserName Availability using ASP.Net

How to Check UserName Availability using ASP.Net


Hi all,

in previous posts i provide many examples how to check username Availability

Check UserName Availability with JQuery using Memebership

JQuery to Check User Name Availability from Database

Check UserName Availability with AJAX

Check UserName Availablity

Check UserName Availability with Membership

Check UserName Availability

and now i’m going to provide another way to check username Availability using AJAX with Membership

<asp:ScriptManager ID="sm" runat="server" />
<asp:UpdatePanel runat="server" ID="up1">
  <ContentTemplate>
    Username: <asp:TextBox runat="server" id="Username"
    AutoPostBack="true" OnTextChanged="Username_Changed" />
    <div runat="server" id="UserAvailability"></div><br />
  </ContentTemplate>
</asp:UpdatePanel>

and in code behind :-

protected void Username_Changed(object sender, EventArgs e)
{
  if (Membership.GetUser(Username.Text) != null)
  {
    UserAvailability.InnerText = "Username taken, sorry.";
    UserAvailability.Attributes.Add("class", "taken");
  }
  else
  {
    UserAvailability.InnerText = "Username available!";
    UserAvailability.Attributes.Add("class", "available");
  }
}

and the css


body
{
  font-family: Verdana, Sans-Serif;
  font-size: 10pt;
}

label, input
{
  height: 14px;
  margin-bottom: 5px;
}

label
{
  float: left;
  text-align: right;
  margin-right: 20px;
  width: 75px;
}

input
{
  float: left;
}

br
{
  clear: both;
}

#UserAvailability
{
  padding-left: 22px;
  margin-left: 5px;
  float: left;
  background-position: left;
  background-repeat: no-repeat;
}

Hope this helps

Good Luck

Advertisements
Categories: AJAX, ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: