473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

CHALLENGE : Detect changes on form in a generic way

I have a form developed in ASP.net and as such all of my controls are
server controls and do not have access to onchange events.

What I need is a javascript program to detect changes.

Here is my idea... when the page loads the program cycles through all
of the objects in the form and saves their values into a variable.
Then, when the user attempts to navigate away the program cycles
through all of the objects in the form and saves the values into
another variable. It checks the first variable agains the second and
if different asks the user if they want to discard their changes.

I do not have the javascript skills to do this but maybe someone else
does? Or someone can tell me this is impossible? By the way I am
willing to pay up to $100 US for a reasonable solution.

Jon Bosker
www.dbgurus.com.au

Feb 6 '07 #1
2 1955
JonBosker wrote:
I have a form developed in ASP.net and as such all of my controls are
server controls and do not have access to onchange events.
What I need is a javascript program to detect changes.
See isFormModified at
http://www.mattkruse.com/javascript/...ns/source.html
Here is my idea... when the page loads the program cycles through all
of the objects in the form and saves their values into a variable.
No need, since the default value is a property of each element and can be
compared to the current value.
By the way I am
willing to pay up to $100 US for a reasonable solution.
I accept Paypal ;)

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Feb 7 '07 #2
Thanks to Matt Kruse (http://www.JavascriptToolbox.comhttp://
www.AjaxToolbox.com) for providing the majority of the solution.

Ideally I would have liked to use the onunload event, or even the
onbeforeunload event but it seems from my research that is not
possible to get either of these events to cancel. Strange but
apparently true.

Matt very kindly provided an unpdate to his code to handle the command
buttons I had on my form
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Modify this part of the function:
for (i=0;i<theform.elements.length;i++) {
var changed=false;
var name=theform.elements[i].name;
if(!isBlank(name)){
var type=theform.elements[i].type;
if(!ignoreFields[name]){
if(type=="hidden"&&hiddenFields[name])
{changed=isChanged(theform[name]);}
else if(type=="hidden"){changed=false;}
else {changed=isChanged(theform[name]);}
}
}
if(changed){return true;}
}
return false;
}

to be this:

for (i=0;i<theform.elements.length;i++) {
var changed=false;
var name=theform.elements[i].name;
if(!isBlank(name)){
var type=theform.elements[i].type;
if(type!="submit" && type!="reset" && !ignoreFields[name]){ // THIS
LINE IS
CHANGED
if(type=="hidden"&&hiddenFields[name])
{changed=isChanged(theform[name]);}
else if(type=="hidden"){changed=false;}
else {changed=isChanged(theform[name]);}
}
}
if(changed){return true;}
}
return false;
}
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

and then for the really simple ones amongst us who have little idea
about javascript etc this is what I did:

1. Modified the file validations.js in the way described above.

2. I then added my own simple function to this file:

function confirmExit()
{
if (isFormModified(document.form2, null, null))
{
return (confirm('Are you sure you wish to lose your unsaved
changes?'))
}
return true;
}

3. I added this line into my ASP.net page between the </BODYand
<HEADtags:
<script src="validations.js"></script>

4. On each of my controls that could potentially cause data loss I
added this command (this is in ASP.net - in javascript I guess it
would be onclick)
OnClientClick="return confirm('Are you sure you want to delete
this record?');"

Thats it. It works. Hope that is helpful for someone else.

Jon Bosker
www.dbgurus.com.au

Feb 8 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Stuart | last post by:
Hi All, I got a challenge to make the same APS/Script/Html run on different web roots. I can not use relative pathing in a lot of cases. We use lots of included files so depending on where that...
4
by: vulcaned | last post by:
Hi All, Hopefully I explain this well........ In Access97 I have a form which has a tab control on it, each tab has a sub-form which is bound to its appropriate table(I'll call them 'Detail'...
1
by: Ludovic Lemarinel | last post by:
Hi, I've got a Tab Control, with a lot of tabs, and a lot of controls in each tab (textboxes, comboboxes, listviews, checkboces, etc...). As these controls are updating a Database, I need to...
1
by: Bob | last post by:
I am developing a database app using vb.net and SQL Server. I am trying to come up with a way I can detect if the user has made any changes/updates to any data currently displayed on the form so that...
7
by: ljlevend | last post by:
Is there any way (either .NET or API) to detect when Windows.Forms.Form.ActiveForm changes? Thanks, Lance
0
by: asad.naeem | last post by:
Hi All i have some forms in my application. They are all inherited from a single form. I have also used typed datasets on my inherited forms. But i dont want to use dataset.Getchanges() for this...
0
by: MarkusR | last post by:
Good day, I have an untyped table. How do I detect if the user is still editing a record when they try to switch tab pages or close the form? I want to tell them to cancel or save their...
1
by: tm123456789 | last post by:
Are you confident that you fully understand Generics? Here's a challenge to see if you do. Below is a simple test app that creates an array of a generic type and attempts to sort it. The...
2
by: GS | last post by:
How do I properly detect row change before allowing moving to next row? I tried using RowLeave . here is brief descript of the form setup. I have ieStringTmpDataSetwith regex table...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.