Assigning C# variable value using javascript variable in code behind
16,630
There is no way to assign a C# variable by javascript. You have to send that value from the client (where you JavaScript is running) to the Server, and assign it. This is so called ajax request, just google it and you'll find millions of good examples of how to achieve that.
Comments
-
ankita alung almost 2 years
I am trying to access the script variable
pic
and assign it to another variable in C#, say hidden fieldhdn
. The script below is also placed on the same code behind page for some reason. I can directly access the hidden field here. But how do I assign it value from the script variable?<script type=\"text/javascript\"> $(document).ready(function() { $.get('<%=completeURL%>', function(d) { $(d).find('entry').each(function(){ var $entry = $(this); var pic = $entry.find('content').attr('src'); alert(pic); }); }); }); </script>