How do I know when the user makes changes on a web form?

Discussion in 'ASP .Net' started by Vinay, Sep 26, 2003.

  1. Vinay

    Vinay Guest

    Hi All:

    I have a web form that is displaying some data. What I want to do is:

    - Set a flag when the user modifies any data on the form
    - Ask the user if the changes are to be discarded when the user hits the exit button
    - If user says Yes/OK I continue and quit the screen
    - If user says Cancel I stop and return to the screen.

    Here is what I have tried:

    In the page_load event I have added the following code:

    cmdCancel.Attributes.Add("onclick", "return confirm('Quit without saving?')")

    But this causes it to fire even if there is no change - I (my client) want this to fire only if there is a change.

    So I tried to add the same line in the _TextChanged event of a textbox control. The idea being once the user saves the form contents by hitting 'Save' I will use cmdCancel.Attributes.Remove("onclick") and add it back when _TextChanged detects a change.

    This is not working right - I guess the way I have tried to implement it is flawed.

    Is there anything other way I can do this?

    Any help would be much appreciated.

    TIA!

    Vinay
    Vinay, Sep 26, 2003
    #1
    1. Advertising

  2. "Vinay" <> wrote in message news:...
    Hi All:

    I have a web form that is displaying some data. What I want to do is:

    - Set a flag when the user modifies any data on the form
    - Ask the user if the changes are to be discarded when the user hits the exit button
    - If user says Yes/OK I continue and quit the screen
    - If user says Cancel I stop and return to the screen.

    Here is what I have tried:

    In the page_load event I have added the following code:

    cmdCancel.Attributes.Add("onclick", "return confirm('Quit without saving?')")

    But this causes it to fire even if there is no change - I (my client) want this to fire only if there is a change.

    So I tried to add the same line in the _TextChanged event of a textbox control. The idea being once the user saves the form contents by hitting 'Save' I will use cmdCancel.Attributes.Remove("onclick") and add it back when _TextChanged detects a change.

    This is not working right - I guess the way I have tried to implement it is flawed.

    Is there anything other way I can do this?
    You'll have to do this client-side, with JavaScript.
    --
    John Saunders
    Internet Engineer
    John Saunders, Sep 27, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vinay
    Replies:
    0
    Views:
    375
    Vinay
    Sep 29, 2003
  2. Casper Skovgaard

    How do I check for changes in a user form?

    Casper Skovgaard, May 6, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    496
    Rick Spiewak
    May 6, 2004
  3. Matthew Nicoll

    IE makes Form in table cell double height

    Matthew Nicoll, Sep 8, 2004, in forum: HTML
    Replies:
    2
    Views:
    5,946
  4. Raj
    Replies:
    0
    Views:
    153
  5. Andries

    I know, I know, I don't know

    Andries, Apr 23, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    227
    Gregory Toomey
    Apr 23, 2004
Loading...

Share This Page