protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { var PersonId = Request.QueryString["ID"]; PeopleService peopleService = new PeopleService(); Contso.Model.People people = peopleService.GetById(Convert.ToInt32(PersonId)); LblId.Text = people.id.ToString(); LblLastName.Text = people.LastName; LblFirstName.Text = people.FirstName; LblMiddleName.Text = people.MiddleName; LblAge.Text = people.Age.ToString(); LblEmail.Text = people.Email; LblPhone.Text = people.Phone; LblAddressLine1.Text = people.AddressLine1; LblAddressLine2.Text = people.AddressLine2; LblUnitOrApartmentNumber.Text = people.UnitOrApartmentNumber; LblCity.Text = people.City; LblState.Text = people.State; LblZipcode.Text = people.Zipcode; LblCreatedDate.Text = people.CreatedDate.ToString(); LblCreatedBy.Text = people.CreatedBy; LblUpdatedDate.Text = people.UpdatedDate.ToString(); LblUpdatedBy.Text = people.UpdatedBy; LblSalt.Text = people.Salt; LblIsLocked.Text = people.IsLocked; LblLastLockedDateTime.Text = people.LastLockedDateTime.ToString(); LblFailedAttempts.Text = people.FailedAttempts.ToString(); } }
protected void btnSave_Click(object sender, EventArgs e) { if (Page.IsValid) // if invalid, browser won't even go here, then why use this? // because if user disables javascript, .aspx validation won't work, this is a backup. { Contso.Model.People obj = new Contso.Model.People(); obj.FirstName = txtFirstName.Text; obj.LastName = txtLastName.Text; obj.MiddleName = txtMiddleName.Text; obj.Age = Convert.ToInt32(txtAge.Text); obj.Email = txtEmail.Text; obj.Phone = txtPhone.Text; obj.AddressLine1 = txtAddressLine1.Text; obj.AddressLine2 = txtAddressLine2.Text; obj.UnitOrApartmentNumber = txtUnitOrApartmentNumber.Text; obj.City = txtCity.Text; obj.State = ddlState.SelectedValue; obj.Zipcode = txtZipcode.Text; obj.CreatedDate = Convert.ToDateTime(txtCreatedDate.Text); obj.CreatedBy = txtCreatedBy.Text; obj.UpdatedDate = Convert.ToDateTime(txtUpdatedDate.Text); obj.UpdatedBy = txtUpdatedBy.Text; obj.Salt = txtSalt.Text; obj.IsLocked = txtIsLocked.Text; obj.LastLockedDateTime = Convert.ToDateTime(txtLastLockedDateTime.Text); obj.FailedAttempts = Convert.ToInt32(txtFailedAttempts.Text); PeopleService peopleService = new PeopleService(); peopleService.Insert(obj); } }