I'm evaluating two options of accessing a server side data on client side. Little bit confused about the efficiency or may be you can call it as finding best approach to do it.
I need to access a server side data may be an integer value in javascript on client side. I know about two options to do it.
Create a public variable or property on server side and set it to javascript variable on client side as below:
var value = eval(<% =value %>);
Create a asp hidden variable and set value in this hidden variable from server side and access it through javascript u开发者_开发知识库sing document.getElementById().
Which is the best approach and what are the pros and cons?
The main difference is that the hidden field will be posted back with the rest of the form fields when the form is submitted. Most people will go this route vs introducing a global javascript variable but if that works for your scenario it is fine.
精彩评论