How do I check for changes in a user form?

  • Thread starter Thread starter Casper Skovgaard
  • Start date Start date
C

Casper Skovgaard

I have a form with several fields (textbox, radio, checkbox), when the user
submits the form I want to check if the user have changed anything.

The check should be performed in the code-behind file.

Is this possible?


/Casper
 
if you want to check using Request.Form[""], you cannot access the default
value.
If you want to perform this check only for server controls, you can have
Changed event handlers for all controls.

for html controls, you have to perform the check on the client side using
script.

Av.
 
I only need to check for server controls. I have tried to do the
following:

On the controls I have added a OnTextChanged
<asp:textbox OnTextChanged="OnDocumentChanged"....

And created this method in the code-behind file
private bool IsDocumentChanged;

protected void OnDocumentChanged(object src, EventArgs e)
{
// event handler for all input fields
IsDocumentChanged = true;
}

The problem with that solution is that OnDocumentChanged is first
executed after Page_Load. I need to do one thing when then input is
changed and another thing if the input is not changed. I can't see how to
do that???

/Casper

if you want to check using Request.Form[""], you cannot access the
default value.
If you want to perform this check only for server controls, you can
have Changed event handlers for all controls.

for html controls, you have to perform the check on the client side
using script.

Av.

Casper Skovgaard said:
I have a form with several fields (textbox, radio, checkbox), when the
user
submits the form I want to check if the user have changed anything.

The check should be performed in the code-behind file.

Is this possible?


/Casper
 
Check for postback in your event handler first, don't set IsDocumentChanged
unless it is a postback.

Casper Skovgaard said:
I only need to check for server controls. I have tried to do the
following:

On the controls I have added a OnTextChanged
<asp:textbox OnTextChanged="OnDocumentChanged"....

And created this method in the code-behind file
private bool IsDocumentChanged;

protected void OnDocumentChanged(object src, EventArgs e)
{
// event handler for all input fields
IsDocumentChanged = true;
}

The problem with that solution is that OnDocumentChanged is first
executed after Page_Load. I need to do one thing when then input is
changed and another thing if the input is not changed. I can't see how to
do that???

/Casper

if you want to check using Request.Form[""], you cannot access the
default value.
If you want to perform this check only for server controls, you can
have Changed event handlers for all controls.

for html controls, you have to perform the check on the client side
using script.

Av.

Casper Skovgaard said:
I have a form with several fields (textbox, radio, checkbox), when the
user
submits the form I want to check if the user have changed anything.

The check should be performed in the code-behind file.

Is this possible?


/Casper
 
Back
Top