一个 .aspx 页面中有两个表单标记
我遇到以下问题 - 我有一个带有 ASP 菜单控件的母版页,该母版页由网站的每个内容页继承。
问题是,在(几乎)每个内容页面中,我都有一个带有 runat = "server"
的表单,并且出现编译错误,指出我不能有 2 个带有 runat = " 的表单标签服务器”
在一个页面中(因为我必须将菜单控件放在另一个表单标记中)。
我该怎么办?我正在将其作为 C#/ASP.NET 大学课程的课程项目来做,作业中说我们必须使用母版页,并且必须使用 asp 导航控件进行站点导航,所以我不能使用清晰的 html 菜单或删除母版页...
I'm having the following problem - I have a master page with an ASP menu control on it which is inherited by every content page of the web site.
The thing is that in (almost) every content page I have a form with runat = "server"
and I get a compile error that I can't have 2 form tags with runat = "server"
in one page (since I must put the menu control in another form tag).
How should I go about it? I'm doing this as a course project for a university course in C#/ASP.NET and it is said in the asignment that we must use master pages and we must use the asp navigation controls for the site navigation, so I can't use clear html for the menu or drop the master pages...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一个也是最简单的选择是从实际页面中删除表单并使用单个表单来处理所有内容。 ASP.NET Web 窗体就是为了这种方式而设计的。因为这是一个大学项目,所以没问题。
更好的方法是使用客户端(没有 runat="server" 形式)。您可以使用 Request.Form 对象以某种“PHP 方式”手动处理帖子并从中读取值。如果您需要使用 ASP.NET 菜单控件,则此方法将不起作用。所以基本上你不能根据需求使用这种方法。
PS 为什么这篇文章带有 ASP.NET MVC 标签?如果您使用 ASP.NET MVC,则不应出现此问题。但还有其他问题。
The first and easiest option is to remove the forms from the actual pages and use a single form for everything. ASP.NET Web Forms is designed to work that way. Since it is a university project this will be fine.
The better way is to use client side (no runat="server" form). You can handle the posts manually in a sort of "PHP fashion" by using the Request.Form object and read values off of it. This will not work if you are required to use the ASP.NET menu controls. So basically you cannot use this approach based on requirements.
P.S. Why is the post tagged with ASP.NET MVC tag? You should not have this problem if you are using ASP.NET MVC. There are other problems though.