i have these codes username , email validation if existing in database or not. far able make them work(validations appear) however, though example username exists , clicked on submit, still pushes through? missing here?
protected void txtuser_textchanged(object sender, eventargs e) { if (!string.isnullorempty(txtuser.text)) { sqlconnection conn = new sqlconnection(configurationmanager.connectionstrings["registrationconnectionstring"].connectionstring); conn.open(); sqlcommand cmd = new sqlcommand("select * userdata username=@username", conn); cmd.parameters.addwithvalue("@username", txtuser.text); sqldatareader dr = cmd.executereader(); if (dr.hasrows) { lblusercheck.text = "username exists"; lblusercheck.forecolor = system.drawing.color.red; imgstatus.visible = true; imgstatus.imageurl = "images1/work/notavailable.png"; } else { lblusercheck.text = "username available!"; lblusercheck.forecolor = system.drawing.color.limegreen; imgstatus.visible = true; imgstatus.imageurl = "images1/work/available.png"; } conn.close(); } } protected void txtemail_textchanged(object sender, eventargs e) { if (!string.isnullorempty(txtemail.text)) { sqlconnection conn = new sqlconnection(configurationmanager.connectionstrings["registrationconnectionstring"].connectionstring); conn.open(); sqlcommand cmd = new sqlcommand("select * userdata email=@email", conn); cmd.parameters.addwithvalue("@email", txtemail.text); sqldatareader dr = cmd.executereader(); if (dr.hasrows) { lblemailcheck.text = "email used"; lblemailcheck.forecolor = system.drawing.color.red; imageemail.visible = true; imageemail.imageurl = "images1/work/notavailable.png"; } else { lblemailcheck.text = "email approved"; lblemailcheck.forecolor = system.drawing.color.limegreen; imageemail.visible = true; imageemail.imageurl = "images1/work/available.png"; } conn.close(); } and here submit button code:
protected void btn_registration_click(object sender, eventargs e) { try { sqlconnection conn = new sqlconnection(configurationmanager.connectionstrings["registrationconnectionstring"].connectionstring); conn.open(); string insertquery = "insert userdata(username,firstname,lastname,email,password,customertype,deliveryaddress,zip,contactnumber)values(@username,@firstname,@lastname,@email,@password,@customertype,@deliveryaddress,@zip,@contactnumber)"; sqlcommand scm = new sqlcommand(insertquery, conn); scm.parameters.addwithvalue("@username", txtuser.text); scm.parameters.addwithvalue("@firstname", txtfn.text); scm.parameters.addwithvalue("@lastname", txtln.text); scm.parameters.addwithvalue("@email", txtemail.text); scm.parameters.addwithvalue("@password", businesslayer.shoppingcart.createshahash(txtpw.text)); scm.parameters.addwithvalue("@customertype", radiobuttonlist1.selecteditem.tostring()); scm.parameters.addwithvalue("@deliveryaddress", txtaddress.text); scm.parameters.addwithvalue("@zip", txtzip.text); scm.parameters.addwithvalue("@contactnumber", txtcontact.text); scm.executenonquery(); session["contact"] = txtcontact.text; session["email"] = txtemail.text; session["deliveryaddress"] = txtaddress.text; label_register_success.text = ("registration successful!"); //response.redirect("home.aspx"); conn.close(); } catch (exception ex) { response.write("error:" + ex.tostring()); } }
Comments
Post a Comment