How can I pass my JSON with asp.net button control's OnClick event to its event handler? Because OnClick will be set to an event handler. I don't see a way to send data as argument. I have figured out an alternative with jQuery.Ajax but I would still like to know how to do it orwhether its possible or viable.
Add a comment
|
1 Answer
You could send it as a normal POST value, lets say a HiddenField.
Steps:
- Define a HiddenField on the page.
- Fill it with the JSON value on the client side before posting back.
- On the button event handler, grab the HiddenField's value, which would be the JSON.
- Parse the Value and do what you have to do.
Another way would be to implement the IPostBackEventHandler interface on your control/page and do the postback directly to them instead of using the buttons postback. In this case you could pass the JSON value directly on the call to the ASP.NET __doPostBack javascript function.