Why you can't have a page with multiple server-side Form tags?
I wonder why asp.net doesn't allow this? Lot's of pages contain more than 1 form, Login - Register forms, search - other forms and so on...
So My guess is I can associate one form with fine oop asp.net objects and other with plain html and I have to handle the response from these froms in two complete seperate ways. Is that right?
Please explain what's going on here, and开发者_高级运维 why asp.net doesn't allow this
ASP.NET webforms relies on having a single server side form.
You can add as many client side forms as you want (no runat="server"
attribute).
This is due to the attempt to have a desktop like development model for web development.
See this MSDN magazine article for more reasons:
The single-form model is a key element for the implementation of the ASP.NET state maintenance feature. Since the page always posts to itself, the runtime finds it easy to retrieve and restore the state saved during the last access. While there are other ways to save and restore the state of a page, using a single-form model is by far the simplest and most effective of all solutions.
In general, renouncing multiple forms is not a big sacrifice. Multiple forms are sometimes useful, but probably not as frequently as you may think. A scenario in which you would find it helpful to use multiple forms is when you implement form-based functionality in a large number of pages—in search and login dialogs, for example. I'll return to this later in the column. Before going any further, though, a review of the HtmlForm class is in order.
Note:
ASP.NET-MVC has no such limitation - you can have as many forms as you like.
ASP.NET was built with a desktop-like mindset. In other words, it was built to provide desktop developers with a desktop-like platform for building websites. In order to support this initiative the designers of ASP.NET decided that the entire page should be wrapped in one big form and that form would be the only form on the page so that all the controls on the page would have a common root from which to POST data to the server.
If multiple runat="server"
forms were allowed then that would require that ASP.NET developers learn more about HTML/HTTP then was desired. The goal was to allow people to use button click events and select list change events in a way that corresponded to the WinForms model. There was no way to maintain that illusion if the developer needed to know which form was POSTing where.
精彩评论