开发者

Hidden variable Vs Server variable accessing on client side in javascript

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.

  1. Create a public variable or property on server side and set it to javascript variable on client side as below:

    var value = eval(<% =value %>);
    
  2. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜