Access an asp:hiddenfield control in JavaScript

前端 未结 6 1748
南旧
南旧 2020-12-21 00:10

What is the best way to access an ASP.NET HiddenField control that is embedded in an ASP.NET PlaceHolder control through JavaScript? The Visible attribute is set to false i

6条回答
  •  星月不相逢
    2020-12-21 00:34

    If the place holder visibility is set to false, it will never be rendered , and the hidden field value will be only stored in the ViewState of the page.

    just one question, why are you setting the visibility of the place holder to be false , if its containing a hidden field?

    Anyway one possible way to get over this issue, is adding a TextBox or Label object , and set the display CSS style of it to "none" , then in your code copy whatever you are putting in the hidden field into the textbox/lable text property, this way you can easily read the value using javascript , since the textbox/label will be rendered but not visible to others, though this might not be that safe thing to do.

提交回复
热议问题