Creating an HTML hidden control from code behind

夙愿已清 提交于 2019-12-25 10:09:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!