jquery to check Email availability/duplication in database

Attenlidist

New Member
I am trying to check Email availability on text change event of a textbox. Below is the code (I picked up from the net):HTML (javascript):\[code\] <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script><script type="text/javascript"> $(document).ready(function () { $("#<%=txtEmailAddress.UniqueID%>").change(function () { var uname = $("#<%=txtEmailAddress.UniqueID%>"); var msgbox = $("#status"); if (Email.val().length > 0) { $.ajax({ type: "POST", url: "SignUp.aspx/usp_CheckEmail", data: "{'args': '" + Email.val() + "'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { if (msg.d == 'Available') { Email.removeClass("notavailablecss"); Email.addClass("availablecss"); msgbox.html('<img src="http://stackoverflow.com/questions/15564792/Images/a.png"> <font color="Green"> Available </font>'); } else { Email.removeClass("availablecss"); Email.addClass("notavailablecss"); msgbox.html(msg.d); } } }); } else { Email.addClass("notavailablecss"); msgbox.html('<font color="#cc0000">Email must be unique</font>'); } }); });\[/code\]CS:\[code\] [System.Web.Services.WebMethod]protected void txtPassword_TextChanged(object sender, EventArgs e, string args) { string returnValue = http://stackoverflow.com/questions/15564792/string.Empty; SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["ConnectionString"]);try{SqlCommand sqlCmd = new SqlCommand("usp_CheckEmail", con);sqlCmd.CommandType = CommandType.StoredProcedure;sqlCmd.Parameters.AddWithValue("@Email", args.Trim());con.Open();int success = int.Parse((sqlCmd.ExecuteScalar().ToString()));if(success == 1) // Email Not Available{returnValue = "http://stackoverflow.com/questions/15564792/<img src="Images1/n.png"><font color="#cc0000"><b>'" + args + "'</b> is already in use.</font>"; **//getting syntax error here** } else if(success == 0)//Email is available{ returnValue = "http://stackoverflow.com/questions/15564792/Available"; }} catch { //Handle Error } finally { con.Close(); }return returnValue; } } }\[/code\]Getting an error in the return value line. What would be the correct syntax?? Also, it is supposed to display images like this:
H36Lx.png
So, do I need to have image controls on my .aspx page? Because the article that I got this code from, did not mention to have image controls. And if yes, how do I bind them with the code then??UPDATE: heres the link to where I got the code fromhttp://www.dotnetspark.com/kb/Content.aspx?id=1278What all things are missing from the article?? what else needs to be done? Anyone please.. I need this...
 
Back
Top