Vs Server hidden variable available on client side in javascript

I evaluate two options for accessing data on the server side on the client side. Confuse a little about efficiency, or maybe you can call it as the best approach for this.

I need to access data on the server side, maybe an integer value in javascript on the client side. I know about two options.

  • Create a public variable or property on the server side and set the client-side javascript variable for it, as shown below:

    var value = eval(<% =value %>);
    
  • Create a hidden asp variable and set the value in this hidden variable on the server side and access it through javascript using document.getElementById ().

What is the best approach and what are the pros and cons?

+3
source share
1 answer

The main difference is that the hidden field will be sent back with the rest of the form fields when the form is submitted. Most people will go this route instead of introducing a global javascript variable, but if that works for your script, that's fine.

+3
source

Source: https://habr.com/ru/post/1754546/


All Articles