Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning C# variable value using javascript variable in code behind

I am trying to access the script variable pic and assign it to another variable in C#, say hidden field hdn. 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>
like image 616
ankita alung Avatar asked Dec 11 '25 05:12

ankita alung


1 Answers

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.

like image 98
MichaC Avatar answered Dec 12 '25 18:12

MichaC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!