一个页面只能有一个服务器端Form标签
我已阅读其他结果,但没有具体针对我的问题。
我意识到有两个带有 runat="server" 的表单标签不起作用。我的问题是,我需要母版页文件中的一个表单来处理菜单等,并且我的应用程序的“子”页面还需要一个表单标记来处理其操作。
我尝试删除“子”页面中的表单标签,但隐藏代码没有看到我在母版页中使用表单标签。因此,编译失败(“名称“form1”在当前上下文中不存在”)
如何实现使母版页中的菜单保持正常工作,同时保持“子”页面在编译时不出错的目标?
I have read the other results, but nothing specific to my issue.
I realize having two form tags with runat="server" does not work. My problem is that I require a form in the Master Page file to handle the menus and such, and the 'child' page of my application also requires a form tag to handle its operations.
I have tried to remove the form tag in my 'child' pages, but the code-behind doesn't see that I am using the form tag in the Master Page. Due to this, compilation fails ("The name 'form1' does not exist in the current context")
How can I attain the goal of keeping my menus in the Master Page working, while keeping my 'child' pages from erroring out when compiling?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您选择从所有子页面中删除所有表单标记(我建议这样做),则可以添加对母版页表单标记的引用作为子页面可以访问的属性。下面是母版页代码:
然后您可以从子页面引用:
如果您在子页面中设置 MasterPageType,您可以使用
this.Master.form1
引用目录(将其添加到子页面的标记页面):If you go the route of removing all the form tags from all the child pages (which I would suggest), you can add a reference to the Master Page's Form tag as a property that can be accessed by the child pages. Here would be the Master Page code behind:
Then you could reference from the child page:
And if you set the MasterPageType in the child pages, you can reference directory with
this.Master.form1
(add this to the markup page of the child page):