简体   繁体   English

从后面的代码创建HTML隐藏控件

[英]Creating an HTML hidden control from code behind

I have a Masterpage application where I want to create a hidden field 我有一个Masterpage应用程序,我想在其中创建一个隐藏字段
<asp:HiddenField ID="hdnField" runat="server" Value=""/>

in order to get the client-side time, so I am following an option suggested "How can i get timezone of the client machine?" 为了获取客户端时间,因此我遵循了一个建议的选项: “如何获取客户端计算机的时区?” . However, since my application is a Masterpage app, my question is: where should I create the hidden control in the aspx file (in the .master file... or in the child aspx page or should I create it on the page_load event on the .cs page) ? 但是,由于我的应用程序是Masterpage应用程序,所以我的问题是:我应该在aspx文件(在.master文件...或子aspx页面中)中创建隐藏控件,还是应该在page_load事件上创建该控件? .cs页面)?

Just add the markup that you have in your question in your .master page. 只需在.master页面中添加问题中的标记即可。 Make sure that it is located inside the <form> tag. 确保它位于<form>标记内。

Your script (also in the masterpage) would look like this: 您的脚本(也在母版页中)如下所示:

document.getElementById("<%=this.hdnField.ClientID%>").value = "...";

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

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