Skip to content Skip to sidebar Skip to footer

Firing Postback From Javascript

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 s

Solution 1:

Wow, no answers. Who would've thought this is so obscure.

Anyway, here's what worked for me. I just added an ASP.NET HiddenField to my form with a server-side handler for the ValueChanged event.

<asp:HiddenFieldID="MyHidden"runat="server"OnValueChanged="MyHidden_ValueChanged" />

Then, in response to a user action, my JavaScript sets the value of this hidden field.

$('#<%= MyHidden.ClientID %>').val(myData);

And, finally, in order to trigger the hidden field's ValueChanged event, I initiate a postback with the following code. GetPostBackEventReference() returns a JavaScript statement, which will replace the server side markup.

<%= Page.ClientScript.GetPostBackEventReference(MyHidden, String.Empty) %>;

And it seems to work just fine. A postback occurs, and my ValueChanged handler is called. That handler determines the value of my hidden field and performs the required actions.

Post a Comment for "Firing Postback From Javascript"