protected void ButtonReg_Click(object sender, EventArgs e) { if (txtUName.Text != "" && txtPass.Text != "" && txtPass2.Text != "" && txtFName.Text != "" && txtLName.Text != "" && txtSal.Text != "" && txtAddress.Text != "" && txtCity.Text != "" && txtZip.Text != "" && txtEmail.Text != "") { try { //try and register new user User user = new User(); //take all values from text boxes and send them to User.cs user.Username = txtUName.Text; if (txtPass.Text != txtPass2.Text) { LabelOutput.ForeColor = System.Drawing.Color.Red; LabelOutput.Text = "Passwords do not match!"; } else { user.Password = txtPass.Text; user.Salutation = txtSal.Text; user.FirstName = txtFName.Text; user.LastName = txtLName.Text; user.Address1 = txtAddress.Text; user.Address2 = txtAddress2.Text; user.City = txtCity.Text; user.StateProvinceID = Convert.ToInt32(dropStateProv.SelectedValue); user.ZipCodePostal = txtZip.Text; user.Email = txtEmail.Text; user.IsReceiveNewsletters = ckBox.Checked; // call addUser method to add user and display success/fail text to user if (user.AddUser() > 0) { LabelOutput.ForeColor = System.Drawing.Color.Green; LabelOutput.Text = "Thank you " + txtUName.Text + "! You have successfully registered as a new user."; } else { LabelOutput.ForeColor = System.Drawing.Color.Red; LabelOutput.Text = "Register Failed.<br />Please verify entered values."; throw new Exception(); } } } catch (Exception ex) { String strEx = ex.Message; LabelOutput.ForeColor = System.Drawing.Color.Red; LabelOutput.Text = "Problem Registering, try again"; } }// end if else { LabelOutput.ForeColor = System.Drawing.Color.Red; LabelOutput.Text = "Problem Registering, some required fields have not been filled."; } }
protected void ButtonSubmit_Click(object sender, EventArgs e) { try { //Create a User object User user = new User(); //Update all fields user.Username = TextBoxUsername.Text; user.Password = TextBoxPassword.Text; user.Salutation = TextBoxSalutation.Text; user.FirstName = TextBoxFirstName.Text; user.LastName = TextBoxLastName.Text; user.Address1 = TextBoxAddress1.Text; user.Address2 = TextBoxAddress2.Text; user.City = TextBoxCity.Text; user.StateProvinceID = Convert.ToInt32(DropDownListStateProvince.SelectedValue); user.ZipCodePostal = TextBoxZipPostalCode.Text; user.Email = TextBoxEmail.Text; user.IsReceiveNewsletters = CheckBoxIsReceiveNewsletters.Checked; user.Created = DateTime.Now; user.Modified = DateTime.MinValue; //Update the product if (user.AddUser() > 0) { ScriptManager.RegisterStartupScript(this, GetType(), "", "window.top.window.$.fancybox.close();", true); //Response.Redirect("~/Admin/Users.aspx"); } else { LabelOutput.ForeColor = System.Drawing.Color.Red; LabelOutput.Text = "Error: Update Failed"; } } catch (Exception ex) { LabelOutput.ForeColor = System.Drawing.Color.Red; LabelOutput.Text = "Error: " + ex.Message; } }