Friday 16 December 2011

How to fire a non static code behind method from a javascript postback

I have found an interesting way of firing code behind methods from javascript functions without creating static web methods and ajax calls.

This in conjunction with an UpdatePanel produces a method that can be called from javascript that does not refresh the page.

If an update panel is used, then its a good idea to use the Id for a control inside the update panel so its marked for asyncrous postback, then differentiate between methods using the event argmument

to post back to the server using a javascript function the following code can be used:



We can then set the code behind to inspect the Request.Form collection for any postback information.

This can be very powerful as potentially any code behind method can be called!

No comments:

Post a Comment