Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Checking for duplicates with Ajax, disallowing form to post

$
0
0
I have a small registration script where a user enters an email address, and on the fly will check to see if the email is already in the database (whereas a prompt will display below the textbox is the email/username is or not available.
But when hitting submit , the form just remains static, it doesnt render an error or post to the database:
 
 
////////Ajax objects on ASPX page<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>

/////////////email textbox encapsulated with asp.net control coding
<asp:UpdatePanel ID="PnlUsrDetails" runat="server"><ContentTemplate><asp:Label ID="LabelEmail" runat="server" Text="Email:" CssClass="BlackText" Width="200px"></asp:Label><asp:TextBox ID="TextBoxEmail" runat="server" Width="250px" AutoPostBack="true" ontextchanged="txtEmail_TextChanged"/></asp:TextBox><asp:RequiredFieldValidator ID="RFVUserEMail" runat="server" ForeColor="Red" Display="None"
                    ControlToValidate="TextBoxEmail" ErrorMessage="Enter a valid Email address.">Email</asp:RequiredFieldValidator><asp:RegularExpressionValidator
                        ID="REVUserEMail" runat="server" ForeColor="Red" Display="None" ControlToValidate="TextBoxEmail"
                        ErrorMessage="Enter Correct E-Mail" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">Email</asp:RegularExpressionValidator><!--placeholder to give status of email taken or not --><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><!--loading gif --><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>
/////////////

////////////
/// code behind method to process the check for duplicate emails

protected void txtEmail_TextChanged(object sender, EventArgs e)
{
if(!string.IsNullOrEmpty(TextBoxEmail.Text))
{
SqlConnection con = new SqlConnection("Data Source=dbaseserver.com; Initial Catalog=mydb; User ID=mydb; Password=1234;");
con.Open();
SqlCommand cmd = new SqlCommand("select * from Users where Email=@Email", con);
cmd.Parameters.AddWithValue("@Email", TextBoxEmail.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;
}
}//need this extra brace?
///end checkdupe


Wondering if there is a page_load, ispostback thing I am overlooking of not taking into account.

thakns in advance
chumley


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>