Hi All,
I have been googling around but cannot find the exact solution, hope somebody here can point me to the right direction, thanks in advance.
Problem Scenario:
Do not try to save webform data into database if it has not been changed, need to achieve this by using viewstate.
Example:
A textbox hold the name of a customer, and user enter their name then click on submit and data is save into the database.
While the code works well on just small number of fields, I have multiple webforms each contains more than 50 fields (mostly textboxes). So I need to check to see if data has actually been change for all the fields in the webform, I know ViewState is storing the state of each control on the webform, so when user click a button causes a postback, data is reload back to the fields. My key question is how to use this last viewstate data to compare currect control data to see if data has been changed? All this is for performance issue, so the website to not hammer the SQL Server database when it is not neccessary.
I was looking for something like:
if(ViewState["txtName"].ToString() == txtName.Text) {
//no change, do not save
}
else {
//data changed, then save
}
But ViewState["txtName"] is actually null, looks as I need to manually assign a value into it at the first place. But Im sure ViewState load the data back into txtName when postback happens. Any ideas?
Thanks.