Link to home
Start Free TrialLog in
Avatar of ttta83
ttta83

asked on

C# - Validate form items

I'm working on a C# page that has a lot of textboxes, drop downs, text areas.

Last Name:
First Name:
Contract #:
Phone:
Email:
Birth date:
Location:
Start Date:
End Date:
Salary:

......

The data will be stored in 3 different tables
EMPLOYEE (EmplID, Last Name, First Name, Phone, Email, Birthdate...)
EMPL_LOC (EmplID, ContractNbr, Location...)
EMPL_SAL (EmplID, StartDate, EndDate, Salary...)

Items are not in order.  #1 (LastName),#2 (FirstName),#4,#5,#6 - Table EMPLOYEE, #3, #7 - Table EMPL_LOC...

Everytime the user clicks on Update button, I want to check to see which item(s) got changed to update appropriate table(s).  For example, if the user only changes "location", I just want to update only EMPL_LOC table.

On PageLoad, I can get all the values on the form

formcount = document.forms(0).length;
            for (i = 0; i < formcount - 1; i++) {
                itemType = document.forms(0).item(i).type;
                switch (itemType) {
                           case "text":
                                          iALL_Items_Values = iALL_Items_Values + document.forms(0).item(i).value.toString().trim();
                                         break;
                           case "select":
                                          iALL_Items_Values = iALL_Items_Values + document.forms(0).item(i).value.toString().trim();
                                         break;
                           case "radio":
                                          iALL_Items_Values = iALL_Items_Values + document.forms(0).item(i).value.toString().trim();
                                         break;
                           case "checkbox":
                                          iALL_Items_Values = iALL_Items_Values + document.forms(0).item(i).value.toString().trim();
                                         break;
}
}                        

When the user clicks on the Update button, I call the function above again to get the values on the screen and compare to the values that I captured on PageLoad to see if there's any changes.

How do I do it for each table, only check #1,#2,#4,#5,#6... to see if table EMPLOYEE needs to be updated, #3,#7... to see if EMPL_LOC needs to be update, and so on...

Thank you very much for your help.
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Honestly, to call the update again is not that bad.  

If you were really dead set on this what I would do is store the original values in the sesssion on load.


so when loading:

Session["Firstname"] = firstname;


Then you can check the textbox values on the update.

bool updEMPLOYEE  = false;

if (Session["FirstName"].ToString() != txtFirstName.Text || Session["LastName"].ToString() != txtLastName.Text)  // add other checks as needed.
   updEMPLOYEE  = true;


if (updEmployee)
   // update statement.
Avatar of ttta83
ttta83

ASKER

Thanks ged325,

I  don't want to update again 'cause we keep track of all the changes.  The trigger will insert a record into history table eveytime we update the main table.

Is there a way that we can compare like your way but without specify the name of the item 'cause I have about 50 ietms on the form.

Thanks again for your help.
ASKER CERTIFIED SOLUTION
Avatar of esolve
esolve
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial