...

View Full Version : Confirm cancel when changes are made



dockies
04-28-2008, 03:13 AM
Hi i am developing a website and i am using ASP.NET 2.0 C# and i was wondering if anyone here could help me with my problem.

here is the scenario.
I have a gridview control with a hyperlink in it that says "EDIT"
when i click the link EDIT the form on that page will be populated with data based on my gridview records.

what i want to do is to check weather or not the data on my form was change. or to make it simple i need to check my form vs my dataset.

and when i click the cancel button if javascript detects the changes it will display a confirm msg asking the user if he wants to save the changes first or not.

but if javascripts detects no changes, it will permit the cancel event without displaying the msg.

I know that i can check weather my textbox and my dataset is not the same, my problem is the checking usually runs inside the server side code, and i need to run my script on the client side to prevent my page to continue.

Help me please. :(

peteyb383
04-28-2008, 03:21 AM
I can help you with the confirmation and based on if they click "OK" or "Cancel", they will continue or not.

Put this onClick command in your submit button:



onclick="if (!confirm('Deletion will be permanent, are you sure you wish to continue?'))return false"

Philip M
04-28-2008, 03:39 PM
You can add to each field:-

onchange = "formChanged()"

<script type = "text/javascript">
var changed = false;
function formChanged() {
changed = true;
}
</script>

and then as peteyb383 suggests:-

onclick="if (changed) {(if !confirm ('Deletion will be permanent, are you sure you wish to continue?')); return false}"



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum