我们可以在一个网页中使用多个表单吗? [英] Can we use multiple forms in a web page?

查看:37
本文介绍了我们可以在一个网页中使用多个表单吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我遇到的所有网页最多都包含一个

标签.为什么不是多个?我想不出为什么多个表单不能在同一个网页中共存.

So far, all the web pages I met contain at most one <form> tag. Why not multiple ones? I can not think of reasons why multiple forms can't coexist within the same web page.

另外,对于 ASP.NET - 为什么所有的服务器控件都放在 标签中?为什么不把它们放在其他地方?

Also, to be specific to ASP.NET - why are all the server controls are placed within the <form> tag? Why not place them somewhere else?

另外,

我注意到在 .aspx 文件中, 标签具有 runat=server 属性,而普通服务器Button 等控件也有.所以看起来也是一个服务器控件.但奇怪的是,我在 Visual Studio 工具箱中找不到它.

I noticed that in an .aspx file, the <form> tag has the runat=server attribute, while a normal server control such as Button also has one. So it seems the <form> is also a server control. But strangely enough, I cannot find it in the Visual Studio Toolbox.

推荐答案

可以有多个表单,with 黑客.

这确实是 WebForms 的缺点.在 ASP.NET MVC 中,您可以实现任意数量的表单(这是网页的有效和正确行为).

It is indeed a shortcoming of WebForms. In ASP.NET MVC you can implement as many forms as you want (and it is valid & correct behavior of web pages).

所有服务器控件都放置在 标签内的原因是允许 WebForms 引擎识别它们,加载它们的值 &从/向 ViewState 保存它们的值.WebForms 中几乎所有控制管理的基础结构都基于这样一个想法,即标签包含您从代码隐藏访问的所有内容.

The reason all server controls are placed inside <form> tag is to allow the WebForms engine to recognize them, load their values & save their values from/to the ViewState. Almost all infrastructure of control management in WebForms is based on the idea that a tag contains everything you access from the code-behind.

这篇关于我们可以在一个网页中使用多个表单吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆