Ok, I know this question has been asked a lot and I've found plenty of information on the Web about this. Unfortunately, none of it really seems to work for me.
Basically, I have some JavaScript running in response to a user event. The JavaScript obtains a bit of information (an int) and then I want to get that back to the server.
The first approach was to use Page.ClientScript.GetPostBackEventReference
to get a valid call to __DoPostBack()
as described here.
I used this method to trigger a postback from a button. This seemed to be working except I get the error:
Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
Next, I tried to use a HiddenField's ValueChanged
event handler. I wrote my handler, but changing the value of the hidden field does not trigger the event. Some form of postback still needs to be triggered somehow.
I don't really understand why I'm having so much trouble with this. Is there a more straight forward way of doing what I need?