Checking Form Element's Default Values to determine if Form Has Changed

Last post 03-23-2007 9:47 AM by FrankM. 4 replies.

Sort Posts:

  • Checking Form Element's Default Values to determine if Form Has Changed

    03-20-2007, 11:30 AM
    • Loading...
    • FrankM
    • Joined on 08-25-2005, 4:03 AM
    • Posts 4

    Has anyone else attempted to write a function that does this in javascript? I have successfully created a function that does so, but it doesn't seem to work due to postbacks. What the function does is loops through the form and checks each element. It checks the element to see if it's default value = current value. This works 100% except for it seems when postbacks happen the element's default values are reset to the current values. So the original default values are lost. Arg! Any ideas? I can post the javascript if needed. Thanks all!  

    P.S. If there's a better way to check if the form has changed please give me your ideas. I have to do this client side rather than server side for multiple reasons.
     

  • Re: Checking Form Element's Default Values to determine if Form Has Changed

    03-20-2007, 1:30 PM
    • Loading...
    • JoshStodola
    • Joined on 01-16-2007, 2:17 PM
    • Heartland of America
    • Posts 3,162

    So the problem is that your values are getting reset on postback?

    Try setting EnableViewState="true" on all your form controls.

    Hope this helps!

    Josh Stodola ← Come check out my blog!
  • Re: Checking Form Element's Default Values to determine if Form Has Changed

    03-20-2007, 1:47 PM
    • Loading...
    • FrankM
    • Joined on 08-25-2005, 4:03 AM
    • Posts 4

    When I say the default values are getting reset, I don't mean that on the postback the textbox values are getting rebinded etc. I mean that the client side element.defaultValue is getting reset to whatever is currently in the control. Here's what's happening

    Page gets loaded initially.

    An empty textbox gets created, so the element.defaultValue = ''

    Then I enter text into the textbox. Textbox = 'some text'

    Then I do an action that causes a postback. When returning from the server the element.defaultValue goes from = '' to = 'some text'.

    So now when I run my function to see if the form has changed it says it hasn't because the defaultValue now = 'some text' and the current value = 'some text'. Does this make sense?

    Thanks for the response. 

  • Re: Checking Form Element's Default Values to determine if Form Has Changed

    03-20-2007, 2:35 PM
    • Loading...
    • JoshStodola
    • Joined on 01-16-2007, 2:17 PM
    • Heartland of America
    • Posts 3,162

    Unless you can somehow reset the defaultValue on the server-side Page_Load, I think you are stuck with having to store the original values in hidden fields and compare the textbox value with the hidden field value instead of defaultValue.

    Hope this helps!

    Josh Stodola ← Come check out my blog!
  • Re: Checking Form Element's Default Values to determine if Form Has Changed

    03-23-2007, 9:47 AM
    • Loading...
    • FrankM
    • Joined on 08-25-2005, 4:03 AM
    • Posts 4
    Thanks for the advice Josh. It seems there's no way to accomplish what I need besides hidden text boxes as you said. Unfortunately that's not a possible solution due to the already heavy load the page already has. I would need to add 30 some hidden text boxes, plus handle multiple gridviews that get updated on the page. I didn't design it; only trying to smooth it out! ha! Thanks again for the advice.
Page 1 of 1 (5 items)
Microsoft Communities
Page view counter