Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am using scrpt manager.
my problem is that when i run this code on local server then it working fine but when i want to run on host server it takes more time to check username avialbilty ( see only progress baar) . what i do .thankyou

ASP.NET
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="scriptmanager1" runat="server">
</asp:ScriptManager>
<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="PnlUsrDetails" runat="server">
<ContentTemplate>
<table>
<tr>
<td>
UserName:
</td>
<td>
<asp:TextBox ID="txtUsername" runat="server" AutoPostBack="true"ontextchanged="txtUsername_TextChanged"/>
</td>
<td>
<div id="checkusername" runat="server"  Visible="false">
<asp:Image ID="imgstatus" runat="server" Width="17px" Height="17px"/>
<asp:Label ID="lblStatus" runat="server"></asp:Label>
</div>
</td>
</tr>
</table>
<div class="divwaiting " id="loadingdiv" style="display:none; margin-left:5.3em">
<img src="LoadingImage.gif" alt="Loading" />Please wait...
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

C#
protected void txtUsername_TextChanged(object sender, EventArgs e)
{
    if(!string.IsNullOrEmpty(txtUsername.Text))
    {
        SqlConnection con = new SqlConnection("Data Source=manvendra;IntegratedSecurity=true;Initial Catalog=erp");
con.Open();
        SqlCommand cmd = new SqlCommand("select * from tbl_admin where UserName=@UserName", con);
        cmd.Parameters.AddWithValue("@UserName", txtUsername.Text);
        SqlDataReader dr = cmd.ExecuteReader();
        if (dr.HasRows)
        {
            checkusername.Visible = true;
            imgstatus.ImageUrl = "NotAvailable.jpg";
            lblStatus.Text = "UserName Already Taken";
            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;
    }
}
Posted
Updated 4-Oct-13 8:37am
v2
Comments
karthik413 4-Oct-13 14:45pm    
May the problem with select query
use
SqlCommand cmd = new SqlCommand("select Username from tbl_admin where UserName=@UserName", con);

instead of select * from from tbl_admin where UserName=@UserName
Try to follow what Karthik said above. Adding to that, I would suggest you to check the net and console of FireBug in FireFox and see which request are taking time and why. You can also see the errors there, if anything found.

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