问题
I have a Masterpage application where I want to create a hidden field<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) ?
回答1:
Just add the markup that you have in your question in your .master page. Make sure that it is located inside the <form>
tag.
Your script (also in the masterpage) would look like this:
document.getElementById("<%=this.hdnField.ClientID%>").value = "...";
来源:https://stackoverflow.com/questions/15682764/creating-an-html-hidden-control-from-code-behind