What can I do to prevent (or enable) to properly set the data to the customer class properties without getting wiped across events? Here is my code thus far:
Expand|Select|Wrap|Line Numbers
- protected void btnSubmit_Click(object sender, EventArgs e)
- {
- Customer existCust = new Customer();
- blowinDT = new dsSMOOTH.SG_Sub_Invoice_CardsDataTable();
- blowinTA = new dsSMOOTHTableAdapters.SG_Sub_Invoice_CardsTableAdapter();
- blowinDT = blowinTA.GetData();
- MAX.USPS.USPSManager m = new MAX.USPS.USPSManager("726STARM2333", true);
- MAX.USPS.Address a = new MAX.USPS.Address();
- a.Address2 = txtAddress.Text;
- a.City = txtCity.Text;
- a.State = txtState.Text;
- MAX.USPS.Address validatedAddress = m.ValidateAddress(a);
- if (validatedAddress == null)
- {
- lblError.ForeColor = System.Drawing.Color.Red;
- lblError.Text = "The address entered was invalid";
- }
- else
- {
- if (chkSameAdd.Checked == true)
- {
- newCust.SInstID = txtInstID.Text;
- newCust.SFirstName = txtFName.Text;
- newCust.SLastName = txtLName.Text;
- newCust.SMiddleInitial = txtMiddleInitial.Text;
- newCust.SAddress = validatedAddress.Address2;
- newCust.Address2 = txtAddress2.Text;
- newCust.SCity = validatedAddress.City;
- newCust.SState = validatedAddress.State;
- newCust.SZip = Convert.ToDouble(validatedAddress.Zip);
- newCust.Insert(newCust);
- lblError.ForeColor = System.Drawing.Color.Green;
- if (newCust.SFirstName != null)
- lblError.Text = "Address Information for " + newCust.FirstName + ", " + newCust.LastName + " and " + newCust.SFirstName + ", " + newCust.SLastName + " has been validated and saved to the database! Ready for next entry.";
- txtFName.Text = "";
- txtLName.Text = "";
- txtInstID.Text = "";
- txtMiddleInitial.Text = "";
- txtAddress.Text = "";
- txtAddress2.Text = "";
- txtCity.Text = "";
- txtState.Text = "";
- txtZip.Text = "";
- txtPhone.Text = "";
- txtEmail.Text = "";
- txtBlowIn.Text = "";
- }
- else
- {
- newCust.FirstName = txtFName.Text;
- newCust.LastName = txtLName.Text;
- newCust.Address = validatedAddress.Address2;
- newCust.City = validatedAddress.City;
- newCust.State = validatedAddress.State;
- newCust.Zip = validatedAddress.Zip + "-" + validatedAddress.ZipPlus4;
- newCust.InstID = txtInstID.Text;
- newCust.Address2 = txtAddress2.Text;
- newCust.BlowInIssue = txtBlowIn.Text;
- newCust.Email = txtEmail.Text;
- newCust.MiddleInitial = txtMiddleInitial.Text;
- double phone = Convert.ToDouble(txtPhone.Text);
- newCust.Phone = String.Format("{0:(###)###-####}", phone);
- if (chkSameAdd.Checked == false)
- {
- newCust.CloneAddress = true;
- newCust.SFirstName = "";
- newCust.SLastName = "";
- newCust.SMiddleInitial = "";
- newCust.SInstID = "";
- newCust.SAddress = "";
- newCust.SAddress2 = "";
- newCust.SCity = "";
- newCust.SState = "";
- }
- newCust.Insert(newCust);
- lblError.ForeColor = System.Drawing.Color.Green;
- if (newCust.SFirstName != null)
- lblError.Text = "Address information for " + newCust.LastName + ", " + newCust.FirstName + " has been validated and saved to the database! Ready for next entry.";
- txtFName.Text = "";
- txtLName.Text = "";
- txtInstID.Text = "";
- txtMiddleInitial.Text = "";
- txtAddress.Text = "";
- txtAddress2.Text = "";
- txtCity.Text = "";
- txtState.Text = "";
- txtZip.Text = "";
- txtPhone.Text = "";
- txtEmail.Text = "";
- txtBlowIn.Text = "";
- }
- }
- }
- protected void chkSameAdd_CheckedChanged(object sender, EventArgs e)
- {
- if (txtFName.Text != string.Empty && txtLName.Text != string.Empty && txtAddress.Text != string.Empty && txtCity.Text != string.Empty && txtState.Text != string.Empty && txtZip.Text != string.Empty)
- {
- Customer existCust = new Customer();
- blowinDT = new dsSMOOTH.SG_Sub_Invoice_CardsDataTable();
- blowinTA = new dsSMOOTHTableAdapters.SG_Sub_Invoice_CardsTableAdapter();
- blowinDT = blowinTA.GetData();
- MAX.USPS.USPSManager m = new MAX.USPS.USPSManager("726STARM2333", true);
- MAX.USPS.Address a = new MAX.USPS.Address();
- a.Address2 = txtAddress.Text;
- a.City = txtCity.Text;
- a.State = txtState.Text;
- MAX.USPS.Address validatedAddress = m.ValidateAddress(a);
- if (validatedAddress == null)
- {
- lblError.ForeColor = System.Drawing.Color.Red;
- lblError.Text = "The address entered was invalid";
- }
- else
- {
- newCust.FirstName = txtFName.Text;
- newCust.LastName = txtLName.Text;
- newCust.MiddleInitial = txtMiddleInitial.Text;
- newCust.Address = validatedAddress.Address2;
- newCust.City = validatedAddress.City;
- newCust.State = validatedAddress.State;
- newCust.Zip = validatedAddress.Zip;
- newCust.Email = txtEmail.Text;
- double phone = Convert.ToDouble(txtPhone.Text);
- newCust.Phone = String.Format("{0:(###)###-####}", phone);
- newCust.CloneAddress = true;
- newCust.Address2 = txtAddress2.Text;
- lblError.ForeColor = System.Drawing.Color.Green;
- lblError.Text = "Billing information for " + newCust.FirstName + " " + newCust.LastName + " has been saved. Please enter the shipping information now.";
- txtFName.Text = "";
- txtLName.Text = "";
- txtInstID.Text = "";
- txtMiddleInitial.Text = "";
- txtAddress.Text = "";
- txtAddress2.Text = "";
- txtCity.Text = "";
- txtState.Text = "";
- txtZip.Text = "";
- txtPhone.Text = "";
- txtEmail.Text = "";
- }
- }
- else
- {
- lblError.ForeColor = System.Drawing.Color.Red;
- lblError.Text = "Please fill out the necessary fields";
- chkSameAdd.Checked = false;
- }
- }
- }