简体   繁体   English

如何将值从javascript变量分配给隐藏字段

[英]how to assign an value from javascript variable to hidden field

function(sender, e) { var **Sessioninfo**= $get(''); function(sender,e){var ** Sessioninfo ** = $ get(''); } }

here from my master page hiiden field i am getting the value in Sessioninfo 从我的主页hiiden字段中,我正在获取Sessioninfo中的值

now in child page i have another hidden field called hfchildpage now i need to assign the Sessioninfo. 现在在子页面中,我还有一个名为hfchildpage的隐藏字段,现在我需要分配Sessioninfo。 value to hfchildpage hfchildpage的价值

can u plz provide the syntax for it thank you 你能提供语法吗谢谢

希望我理解您的意思...将隐藏的输入设置为hfchildpage的id属性,并使用以下命令:

document.getElementById('hfchildpage').value = **the value you want**

It really depends where your control is situated in your page. 这实际上取决于控件在页面中的位置。 FindControl method will not simply find a control anywhere. FindControl方法不会简单地在任何地方找到控件。 ie It the control may not be found if the control is nested within another control, one needs to step down through the control structure. 即如果该控件嵌套在另一个控件中,则可能找不到该控件,因此需要逐步退出该控件结构。

However if the resulting element is named 'ct100_hfchildpage' then this bastardized javascript may do what you are looking for. 但是,如果将结果元素命名为“ ct100_hfchildpage”,则此混混的javascript可能会满足您的要求。

var hfchildpageElement = $get('<%=((Hiddenfield)this.Master.FindControl("ct100_hfchildpage")).ClientID %>');

if(hfchildpageElement) hfchildpageElement.value = 'whatEverYouWant';

That said, I think you should review your code and method of using sessions. 就是说,我认为您应该查看您的代码和使用会话的方法。 Sessions are available server side, they are held server side, and hence not only is it very unusual to be storing and using them via JavaScript on the client side, it is bad practice and may be extremely insecure. 会话在服务器端可用,它们在服务器端保留,因此,不仅在客户端通过JavaScript存储和使用会话是非常不寻常的,而且是不正确的做法,并且可能非常不安全。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM