protected void ButtonSave_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 { usrID = Convert.ToInt32(Session["UserID"]); User usr = new User(); usr.GetUserByID(usrID); //take all values from text boxes and send them to User.cs usr.Username = txtUName.Text; if (txtPass.Text != txtPass2.Text) { LabelOutput.ForeColor = System.Drawing.Color.Red; LabelOutput.Text = "Passwords do not match!"; } else { usr.Password = txtPass.Text; usr.Salutation = txtSal.Text; usr.FirstName = txtFName.Text; usr.LastName = txtLName.Text; usr.Address1 = txtAddress.Text; usr.Address2 = txtAddress2.Text; usr.City = txtCity.Text; usr.StateProvinceID = Convert.ToInt32(dropStateProv.SelectedValue); usr.ZipCodePostal = txtZip.Text; usr.Email = txtEmail.Text; usr.IsReceiveNewsletters = ckBox.Checked; // call addusr method to add usr and display success/fail text to usr if (usr.UpdateUser()) { LabelOutput.ForeColor = System.Drawing.Color.Green; LabelOutput.Text = "Thank you " + txtUName.Text + "! You have successfully changed your information."; } else { LabelOutput.ForeColor = System.Drawing.Color.Red; LabelOutput.Text = "Update 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 Updating, try again"; } }// end if else { LabelOutput.ForeColor = System.Drawing.Color.Red; LabelOutput.Text = "Problem Updating, some required fields have not been filled."; } }
protected void ButtonSubmit_Click(object sender, EventArgs e) { try { //Create a User object User user = new User(); //Get existing user by its id user.GetUserByID(Convert.ToInt32(LabelUserID.Text)); //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.Modified = DateTime.Now; //Update the product if (user.UpdateUser()) { 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; } }