Validate Changed Data Before Submitting

  • Thread starter Thread starter Johnny
  • Start date Start date
J

Johnny

Hello,

I've read somewhere that you can validate form data
before actually submitting it, similar to what validation
controls would do. For example, I have a form that has 2
textboxes. I populate the 2 textboxes with values from
the database. I also have an update button that will
update the values. If I have not made any change to the
data in the textboxes, then I do not want to submit the
data when the update button is clicked. I want to be able
to display a message that says data has not changed. Is
there a way to do this using viewstate or caching the
data.

Thanks,
 
Viewstate is encrypted data that is viewable only on the server. So, you
have two options:

1. Store the current values in either viewstate or a session variable, then
do a comparison on postback to determine if they have changed prior to
updating the database.
2. Run a javascript on the client on the page load event that stores the
current value of these text boxes. Then, have an <input type="button"
onClick="reviewAndSubmit()"> that calls the reviewAndSubmit function
(JavaScript) which compares the current values to the original values, and
if they are different submit, otherwise redirect.
 
Back
Top