如何:在母版页基页中动态添加 HiddenField
我有一个 Base MasterPage 类,我的母版页将从该类继承。我有一些 javascript 函数供其子页面包含。由于它是一个基类,因此它没有可视化设计器,我也无法添加 XHTML 代码。 我需要向类添加一个隐藏字段,以便我可以在 javascript 代码中设置它的值,并且当发生回发时我可以在我的内容页面上获取设置的值。 然而我未能实现这一点,因为当我尝试将隐藏字段添加到基本母版页的控件集合中时,我收到渲染错误(如果在 Firefox 中查看,则出现内容编码错误)。如果我尝试作弊并通过脚本管理器注册具有相同名称的隐藏字段,而不是将控件添加到控件集合中,那么......我得到的值为空。 怎样才能做到这一点呢?
I have a Base MasterPage class, from which my masterpages will inherit. I have some javascript functions there for it's child pages to include. As it's a base class, it does not have a visual designer nor I can add XHTML code.
I need to add a hidden field to the class so I can set it's value in the javascript code, and when a postback occurs I can get the setted value on my content pages.
Yet I fail to achieve this, for when I try to add the hidden field to the base masterpage's control collection I get a render error (Content Encoding error if viewed in Firefox). And If I try cheating and registering a hidden field via scriptmanager with the same name in stead of adding the control to the control collection, well... I get the value as empty.
How could achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过
Request.Form("MyHiddenField1")
访问 HiddenField 的值(因为它不是服务器控件,所以它不是页面控件集合的一部分)。MSDN:HttpRequest.Form-Property
You can access the HiddenField's value via
Request.Form("MyHiddenField1")
(since it's not a servercontrol, it isn't part of the page's control-collection).MSDN: HttpRequest.Form-Property