473,388 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Saving class properties across several events?

Hi, I am currently coding a web form that takes an address and verifies it with the United States Postal Service before inserting the record into a MS Access Database. Along with this, I have a checkbox (with AutoPostBack) that verifies and saves the content in the text boxes as billing information in a customer class before clearing the text fields to enter in the shipping info (newCustomer.sFirstName property for shipping vs. newCustomer.firstName for billing & shipping). My problem lies when I click the checkbox to verify and 'save' the billing address and re-enter the address. The data for the first address gets set to null and I get an error. (cannot enter null into database)

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
  1. protected void btnSubmit_Click(object sender, EventArgs e)
  2.     {
  3.         Customer existCust = new Customer();
  4.  
  5.         blowinDT = new dsSMOOTH.SG_Sub_Invoice_CardsDataTable();
  6.         blowinTA = new dsSMOOTHTableAdapters.SG_Sub_Invoice_CardsTableAdapter();
  7.         blowinDT = blowinTA.GetData();
  8.  
  9.         MAX.USPS.USPSManager m = new MAX.USPS.USPSManager("726STARM2333", true);
  10.         MAX.USPS.Address a = new MAX.USPS.Address();
  11.         a.Address2 = txtAddress.Text;
  12.         a.City = txtCity.Text;
  13.         a.State = txtState.Text;
  14.         MAX.USPS.Address validatedAddress = m.ValidateAddress(a);
  15.         if (validatedAddress == null)
  16.         {
  17.             lblError.ForeColor = System.Drawing.Color.Red;
  18.             lblError.Text = "The address entered was invalid";
  19.         }
  20.         else
  21.         {
  22.             if (chkSameAdd.Checked == true)
  23.             {
  24.                 newCust.SInstID = txtInstID.Text;
  25.                 newCust.SFirstName = txtFName.Text;
  26.                 newCust.SLastName = txtLName.Text;
  27.                 newCust.SMiddleInitial = txtMiddleInitial.Text;
  28.                 newCust.SAddress = validatedAddress.Address2;
  29.                 newCust.Address2 = txtAddress2.Text;
  30.                 newCust.SCity = validatedAddress.City;
  31.                 newCust.SState = validatedAddress.State;
  32.                 newCust.SZip = Convert.ToDouble(validatedAddress.Zip);
  33.                 newCust.Insert(newCust);
  34.  
  35.                 lblError.ForeColor = System.Drawing.Color.Green;
  36.                 if (newCust.SFirstName != null)
  37.                     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.";
  38.  
  39.                 txtFName.Text = "";
  40.                 txtLName.Text = "";
  41.                 txtInstID.Text = "";
  42.                 txtMiddleInitial.Text = "";
  43.                 txtAddress.Text = "";
  44.                 txtAddress2.Text = "";
  45.                 txtCity.Text = "";
  46.                 txtState.Text = "";
  47.                 txtZip.Text = "";
  48.                 txtPhone.Text = "";
  49.                 txtEmail.Text = "";
  50.                 txtBlowIn.Text = "";
  51.             }
  52.             else
  53.             {
  54.                 newCust.FirstName = txtFName.Text;
  55.                 newCust.LastName = txtLName.Text;
  56.                 newCust.Address = validatedAddress.Address2;
  57.                 newCust.City = validatedAddress.City;
  58.                 newCust.State = validatedAddress.State;
  59.                 newCust.Zip = validatedAddress.Zip + "-" + validatedAddress.ZipPlus4;
  60.                     newCust.InstID = txtInstID.Text;
  61.                     newCust.Address2 = txtAddress2.Text;
  62.                     newCust.BlowInIssue = txtBlowIn.Text;
  63.                     newCust.Email = txtEmail.Text;
  64.                     newCust.MiddleInitial = txtMiddleInitial.Text;
  65.                     double phone = Convert.ToDouble(txtPhone.Text);
  66.                     newCust.Phone = String.Format("{0:(###)###-####}", phone);
  67.                     if (chkSameAdd.Checked == false)
  68.                     {
  69.                         newCust.CloneAddress = true;
  70.                         newCust.SFirstName = "";
  71.                         newCust.SLastName = "";
  72.                         newCust.SMiddleInitial = "";
  73.                         newCust.SInstID = "";
  74.                         newCust.SAddress = "";
  75.                         newCust.SAddress2 = "";
  76.                         newCust.SCity = "";
  77.                         newCust.SState = "";
  78.                     }
  79.                     newCust.Insert(newCust);
  80.  
  81.                     lblError.ForeColor = System.Drawing.Color.Green;
  82.                     if (newCust.SFirstName != null)
  83.                         lblError.Text = "Address information for " + newCust.LastName + ", " + newCust.FirstName + " has been validated and saved to the database! Ready for next entry.";
  84.  
  85.                     txtFName.Text = "";
  86.                     txtLName.Text = "";
  87.                     txtInstID.Text = "";
  88.                     txtMiddleInitial.Text = "";
  89.                     txtAddress.Text = "";
  90.                     txtAddress2.Text = "";
  91.                     txtCity.Text = "";
  92.                     txtState.Text = "";
  93.                     txtZip.Text = "";
  94.                     txtPhone.Text = "";
  95.                     txtEmail.Text = "";
  96.                     txtBlowIn.Text = "";
  97.                 }
  98.             }
  99.         }
  100.  
  101.     protected void chkSameAdd_CheckedChanged(object sender, EventArgs e)
  102.     {
  103.         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)
  104.         {
  105.             Customer existCust = new Customer();
  106.  
  107.             blowinDT = new dsSMOOTH.SG_Sub_Invoice_CardsDataTable();
  108.             blowinTA = new dsSMOOTHTableAdapters.SG_Sub_Invoice_CardsTableAdapter();
  109.             blowinDT = blowinTA.GetData();
  110.  
  111.             MAX.USPS.USPSManager m = new MAX.USPS.USPSManager("726STARM2333", true);
  112.             MAX.USPS.Address a = new MAX.USPS.Address();
  113.             a.Address2 = txtAddress.Text;
  114.             a.City = txtCity.Text;
  115.             a.State = txtState.Text;
  116.             MAX.USPS.Address validatedAddress = m.ValidateAddress(a);
  117.             if (validatedAddress == null)
  118.             {
  119.                 lblError.ForeColor = System.Drawing.Color.Red;
  120.                 lblError.Text = "The address entered was invalid";
  121.             }
  122.             else
  123.             {
  124.                 newCust.FirstName = txtFName.Text;
  125.                 newCust.LastName = txtLName.Text;
  126.                 newCust.MiddleInitial = txtMiddleInitial.Text;
  127.                 newCust.Address = validatedAddress.Address2;
  128.                 newCust.City = validatedAddress.City;
  129.                 newCust.State = validatedAddress.State;
  130.                 newCust.Zip = validatedAddress.Zip;
  131.                 newCust.Email = txtEmail.Text;
  132.                 double phone = Convert.ToDouble(txtPhone.Text);
  133.                 newCust.Phone = String.Format("{0:(###)###-####}", phone);
  134.                 newCust.CloneAddress = true;
  135.                 newCust.Address2 = txtAddress2.Text;
  136.  
  137.                     lblError.ForeColor = System.Drawing.Color.Green;
  138.                     lblError.Text = "Billing information for " + newCust.FirstName + " " + newCust.LastName + " has been saved. Please enter the shipping information now.";
  139.                     txtFName.Text = "";
  140.                     txtLName.Text = "";
  141.                     txtInstID.Text = "";
  142.                     txtMiddleInitial.Text = "";
  143.                     txtAddress.Text = "";
  144.                     txtAddress2.Text = "";
  145.                     txtCity.Text = "";
  146.                     txtState.Text = "";
  147.                     txtZip.Text = "";
  148.                     txtPhone.Text = "";
  149.                     txtEmail.Text = "";
  150.  
  151.             }
  152.         }
  153.         else
  154.         {
  155.             lblError.ForeColor = System.Drawing.Color.Red;
  156.             lblError.Text = "Please fill out the necessary fields";
  157.             chkSameAdd.Checked = false;
  158.         }
  159.     }
  160. }
Sorry for the sloppy coding! I'm an amateur, If anyone has any suggestions on how to clean it up, I'm all open!
Jun 15 '10 #1
2 1142
ThatThatGuy
449 Expert 256MB
@Sodapop
Yeah... that code looks real sloppy...

Have you set the ViewState property of the textbox controls to True..
Jun 16 '10 #2
view state's are all set to true. Working on cleaning up the code
Jun 16 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jerry | last post by:
My "main" class is getting a bit long...Is it possble to split a class definition into several files and then import the pieces to get the whole definition? Jerry
7
by: Koda | last post by:
What is the difference between class fields and class properties? Thanks Mike
4
by: Malkocoglu | last post by:
In the good old days , i had a class that had 30 functions (let's say) There was a single include(*.H) file and i could have several implementation(*.CPP) files The reason for doing this is to...
7
by: Dave | last post by:
I was just wondering what the difference between using readonly properties in a class definition instead of using a function? Example: Public Class myClass Private privateValues() as Long '...
11
by: Charles Law | last post by:
I have just been asked how to share functions and properties between two running applications. For example, I have App1 and App2 both running on the same machine. App1 uses a DLL (perhaps) that...
1
by: John Dann | last post by:
I'm realising that there's something important that I don't understand about acccessing class properties. In fact I'm not even sure that I can explain clearly what it is that I don't understand!...
0
by: Andy | last post by:
Hi there, can anyone suggest a simple way to display data on a page across several columns, much like you can in Word when you set the number of columns. Ie you get a newspaper effect: ID ...
6
by: manstey | last post by:
I have a ClassWrapper that wraps around a third party database object. Each database object has a set of properties, like columns in a relational database. I want my wrapper to generate a...
1
by: ggraham | last post by:
I'm a semi-newbie to .NET. I've create a class to handle getting data on a person. It has a couple of properties and a new and save subroutine. I'm loading the data in the page_load even of my...
2
by: metafizzical | last post by:
Hi, I have an object that contains the main data for my script. For example: function Invoice() { this.name="bob" this.email="abc@example.com" } I'm trying to access and edit the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.