Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Apr 2008
    Thanked 0 Times in 0 Posts

    Confirm cancel when changes are made

    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.

  • #2
    Regular Coder
    Join Date
    Mar 2008
    Thanked 9 Times in 9 Posts
    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"
    Last edited by peteyb383; 04-28-2008 at 04:25 AM.

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    London, England
    Thanked 2,573 Times in 2,551 Posts
    You can add to each field:-

    onchange = "formChanged()"

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

    and then as peteyb383 suggests:-

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


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts