我在 ASP.net 应用程序中使用 Page.ClientScript.RegisterHiddenField("hf_Name",value),如何在代码隐藏中为相同的隐藏字段“hf_Name”覆盖或分配新值?
最佳答案
RegisterHiddenField
不会创建服务器端控件,它只是
创建一个普通的 <input type="hidden" name="myhiddenField">
Page.FindControl("myhiddenField")
永远不会在服务器端找到任何东西,甚至 document.getElementById("myhiddenField")
将不会在客户端返回任何内容,因为只分配了名称而不是 ID。
所以如果你需要在服务器端访问它,你应该使用 HiddenField
服务器控件或至少使用 html-input
type=hidden
与 runat="server"
.
关于c# - 为页面ClientScript中的Registered Hidden Field赋值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10604203/