0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.