[英]Access hidden fields value if its Visibility set to false(using C#)
How can I access the content of hidden field, where the hiddenfiled's visibility set to Visible=false
in the server side using C#. 我如何访问隐藏字段的内容,其中在服务器端使用C#将hiddenfiled的可见性设置为
Visible=false
。 I am not in a situation to use CSS's display:none
instead of Visible=false
. 我没有使用CSS的
display:none
代替Visible=false
。
When you set Visisble=false
on the server side it won't actually render the control in the page so there is no way to get the value on the client side. 在服务器端设置
Visisble=false
时,它实际上不会在页面中呈现控件,因此无法在客户端获得该值。
If you really can't put the value in the page some other way you could do an AJAX request to get the value when you need it? 如果您确实无法通过其他方法将值放入页面中,可以在需要时发出AJAX请求以获取值?
If Visible
is false
, then the control did not go down to the client, so you cannot directly access it from javascript: it simply isn't there. 如果
Visible
为false
,则该控件不会传递给客户端,因此您无法直接从javascript访问它:它根本不存在。
Equally, since it is a HiddenField
(ie <input type="hidden"...>
), there is no need to set display:none
- it will never be visible, even if Visible
is true
(although, it will be in the source). 同样,由于它是一个
HiddenField
(即<input type="hidden"...>
),因此无需设置display:none
即使Visible
为true
,它也永远不会可见(尽管它将位于来源)。
So: either set Visible
to true
, or come back to the server to get that value. 因此:将
Visible
设置为true
,或者返回服务器以获取该值。
您不能-这些字段不会呈现给客户端。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.