Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 236 characters in body
Source Link
user3655934
user3655934

The way I typically handle this is by setting a 'dirty' flag any time a data change event occurs on any of the form's controls.

When the user comes to submit the form, I just check the state of the flag to see whether any changes need to be saved. This avoids having to compare all data to their previous states, which can be a nuisance if there are a lot of input controls on the form.

For example:

 bool isDirty; private void textBox_TextChanged(object sender, EventArgs e) { // Possible validation here SetDirty(true); } private void SetDirty(bool dirty) { // Possible global validation here isDirty = dirty; } private void Submit() { if(isDirty) { // Save logic } } 

This approach allows you to run any global validation logic whenever any data is changed.

Caveat: If a user makes a change then reverts it, the form will still submit the data.

The way I typically handle this is by setting a flag any time a data change event occurs on any of the form's controls.

When the user comes to submit the form, I just check the state of the flag to see whether any changes need to be saved.

For example:

 bool isDirty; private void textBox_TextChanged(object sender, EventArgs e) { SetDirty(true); } private void SetDirty(bool dirty) { isDirty = dirty; } private void Submit() { if(isDirty) { // Save logic } } 

This approach allows you to run any global validation logic whenever any data is changed.

Caveat: If a user makes a change then reverts it, the form will still submit the data.

The way I typically handle this is by setting a 'dirty' flag any time a data change event occurs on any of the form's controls.

When the user comes to submit the form, I just check the state of the flag to see whether any changes need to be saved. This avoids having to compare all data to their previous states, which can be a nuisance if there are a lot of input controls on the form.

For example:

 bool isDirty; private void textBox_TextChanged(object sender, EventArgs e) { // Possible validation here SetDirty(true); } private void SetDirty(bool dirty) { // Possible global validation here isDirty = dirty; } private void Submit() { if(isDirty) { // Save logic } } 

This approach allows you to run any global validation logic whenever any data is changed.

Caveat: If a user makes a change then reverts it, the form will still submit the data.

Source Link
user3655934
user3655934

The way I typically handle this is by setting a flag any time a data change event occurs on any of the form's controls.

When the user comes to submit the form, I just check the state of the flag to see whether any changes need to be saved.

For example:

 bool isDirty; private void textBox_TextChanged(object sender, EventArgs e) { SetDirty(true); } private void SetDirty(bool dirty) { isDirty = dirty; } private void Submit() { if(isDirty) { // Save logic } } 

This approach allows you to run any global validation logic whenever any data is changed.

Caveat: If a user makes a change then reverts it, the form will still submit the data.