Monday, July 30, 2012

jquery call asp.net code behind function

The technique I used is 
1) create hidden field in asp.net
2) create hidden button in asp.net

This is used during for example jquery autocomplete where I need to post information back to the servers.
autocomplete call will trigger hidden button onclick.
The codebehind will access the data via hidden field. (note the hidden field onchange only works when there is a form submission. Hence the hidden button was required)


The other way round from codebehind called jquery can be done via
1) Page.registerstartupscripts 
2) clientscript.registerclientscriptblock


jquery set asp.net hidden field can be done:
$("#<%= x.ClientID %>").val() //get
$("#<%= x.ClientID %>").val(newvalue) //set