Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

HiddenField ValueChanged Event

Options
  • 08-01-2009 2:08pm
    #1
    Closed Accounts Posts: 20


    Hi All

    Scenario: A javascript method changes the value of my hidden field to 1000, the ValueChanged Event fires and code executes as expected.

    A short time later the javascript method changes the value of my hidden field to 1000 (same value), the ValueChanged Event does not fire!

    If I change the value to 1001 it fires as expected, but for a good reason I will be changing the value from 1000 to 1000 on a regular basis but I still need the event to fire.

    Any ideas?
    Regards
    Whackhead


Comments

  • Registered Users Posts: 177 ✭✭mercuroman


    Not sure - I've a suggestion but you may find it a bit messy.

    Add a second hidden field, named 1000hiddenfieldchanged (for example) with a default of 0. When the javascript changes the value from then set the 1000hiddenfieldchanged equal to 1. Then call a postback from the javascript (__doPostBack) and check in page_load if 1000hiddenfieldchanged is 1, if it is then call the ValueChanged method, if not then don't.
    You could remove the ValueChanged event from the hidden field and move all the functionality to a new method and just call that method from your page_load. Get your value changing javascript to set 1000hiddenfieldchanged to 1 every time it changes the hidden field value.
    Hope that helps a little


  • Closed Accounts Posts: 20 Whackhead


    Ye, that should work, as you say though, a bit messy. I may edit duplicates on the server side with some sort of duplicate identifier so: 1000, 1000*, 1000**.
    That way the value changes and I can just chop the '*' off in the code behind. Will play around.
    More suggestion welcome.


  • Closed Accounts Posts: 30 codecrunchers


    Hi, I'm not a MS person, but this may help . If your callback method detects the first change of the hidden field, presumably you store it in session or db for future comparisons. Why not then reset the hidden field to -1 or similar since you already have the value you are interested in, on the subsequent change you can compare the new value against the previous one you stored.

    Alan


  • Closed Accounts Posts: 167 ✭✭Deadeyes


    Here's a suggestion, take the code from the valueChanged event and create a new function. Then get rid of the valueChanged event and at the place where javascript is setting the fields value manually call the new function.
    or keep the valueChanged event and when setting the hidden fields value if it is not going to change then manually call the valueChanged event.


Advertisement