Friday, 14 June 2013

Check UserName Availble or Not in asp.net

In Default.aspx:

  <style type="text/css">
        .waitingdiv
        {
            background-color: #F5F8FA;
            border: 1px solid #5A768E;
            color: #333333;
            font-size: 93%;
            margin-bottom: 1em;
            margin-top: 0.2em;
            padding: 8px 12px;
            width: 8.4em;
        }
    </style>
     <script type="text/javascript">
         Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
         function BeginRequestHandler(sender, args) {
             var state = document.getElementById('loadingdiv').style.display;
             if (state == 'block') {
                 document.getElementById('loadingdiv').style.display = 'none';
             } else {
                 document.getElementById('loadingdiv').style.display = 'block';
             }
             args.get_postBackElement().disabled = true;
         }
</script>
    <div>
        <asp:UpdatePanel ID="UpdatePanel" runat="server">
            <ContentTemplate>
                <table>
                    <tr>
                        <td>
                            <strong>UserName: </strong>
                        </td>
                        <td>
                            <asp:TextBox ID="txtUserName" runat="server" AutoPostBack="true" CssClass="serachtext"
                                ontextchanged="txtUserName_TextChanged"></asp:TextBox>
                        </td>
                        <td>
                            <div id="CheckUserName" runat="server" visible="false">
                                <asp:Image ID="imgstatus" runat="server" Height="17px" Width="17px" />
                                <asp:Label ID="lblstatus" runat="server"></asp:Label>
                            </div>
                        </td>
                    </tr>
                </table>
                <div class="waitingdiv" id="loadingdiv" style="display: none; margin-left: 5.3em">
                <img src="LoadingImage.gif" alt="Loading" />Please Wait.......
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>

In Default.aspx.cs:

  protected void txtUserName_TextChanged(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(txtUserName.Text))
        {
            ds = objbal.checkUserName(txtUserName.Text);
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                CheckUserName.Visible = true;
                imgstatus.ImageUrl = "NotAvailable.jpg";
                lblstatus.Text = "UserName Alredy Exists,choose Another One";
                System.Threading.Thread.Sleep(2000);
            }
            else
            {
                CheckUserName.Visible = true;
                imgstatus.ImageUrl = "Icon_Available.gif";
                lblstatus.Text = "UserName Available";
                System.Threading.Thread.Sleep(2000);
            }

        }
        else
        {

            CheckUserName.Visible = false;
        }
    }

Stored Procedure:
create procedure dbo.checkuserId
(
@UserId varchar(50)
)
as
begin
select * from dbo.Cartoon_Admin_Login where UserId=@UserId
end


No comments:

Post a Comment