Why does asp.net wrap a page in a form?

I am a PHP developer who should work on ASP.net projects and I wonder why every page is wrapped in a form. It just doesn't make sense to me.

Also What with all hidden input fields, in particular, "View state".

+7
webforms viewstate
source share
4 answers

ASP.Net is trying to make it possible for programmers to pretend that the web is a stateful platform and that it behaves like a desktop application. ViewState is basically a serialized page state block when it is created. When the page is sent back, the server-side model is initialized with the values ​​in the ViewState, and then the new values ​​from the published form are applied.

Part of becoming a worthy ASP.Net programmer is learning when to use ViewState, and not because it is used everywhere by default, which causes a lot of bloat on the loaded page.

+11
source share

Each ASP.NET page is wrapped with a <form> element, because the whole framework revolves around POST commands.

ASP.NET provides "web controls" that are object-oriented abstractions of HTML elements (and in some cases, groups of elements). In your server code, you can attach commands to various events on web controls (for example, Button.OnClick , TextBox.OnChanged ) - frames lay them using a combination of hidden fields and generated javascript. Generated javascript usually sets the hidden field with several values ​​to indicate (for example) which control triggered the message and command arguments (if applicable), then submits the form.

ViewState is a method used by the environment to serialize client state. This is an alternative to using the session to a large extent, trading large HTML payloads for lower server memory.

+5
source share

Everything in ASP.NET (aspx pages) works with data publishing.

This means that everything that you post to a web page using a server-side action will result in a “backtrack”. The back post contains information such as “what just happened” and some information that helps the web page maintain state (which web pages traditionally don't). View state is part of this stateful task.

If you don't like the way aspx pages try to turn web pages into applications with a fixed form status, you can try the ASP.NET MVC framework, which allows the website to work as intended!

+3
source share

The ASP.NET WebForms engine creates an abstract abstraction by HTTP status without persistence.

The key object is the server page. Monitors fire events that are processed on the server side. Controls maintain their states (usually input values) between requests.

Each time you click on the server element, a request to send back to the server is sent. ViewState actually contains data that tells the server which control triggered the event. That is why there is always a form (and any other forms are not allowed).

+2
source share

All Articles