Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the __VIEWSTATE hidden input element surrounded by <div></div>?

Why does ASP.NET render the hidden __VIEWSTATE input element within <div></div>?

like image 288
Agnel Kurian Avatar asked Jul 22 '12 10:07

Agnel Kurian


1 Answers

They did it to "be more aligned with Web standards" - here is a quote from MSDN Magazine article Enforce Web Standards For Better Accessibility:

There were some well-known deficiencies in ASP.NET 1.1. The out-of-the-box controls produced code that would not pass validation. That was largely attributed to the way that ViewState was handled in ASP.NET 1.1-using a hidden input tag that was not contained within a block display, like this:

<input type="hidden" name="__VIEWSTATE" value="dDwtMTU1NzQzNDgy..." />

This, combined with some other syntactical issues, gave ASP.NET 1.1 an unfortunate reputation for non-compliance.
ASP.NET 2.0 addressed many of the Web standards issues. For example, if you look at the source of ASP.NET 2.0-generated pages, you see that ViewState is now wrapped in a div tag, making it compliant:

<div>
      <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="dDwtMTU1NzQzNDgy..." />
</div>

Microsoft has made it known publicly that one of the goals of ASP.NET 2.0 is to be more aligned with Web standards and, in fact, ASP.NET 2.0 lets you create compliant Web sites and controls. A great resource for building compliant Web sites is Stephen Walther's MSDN® article "Building ASP.NET 2.0 Web Sites Using Web Standards". This 78-page article goes into great detail on building sites according to Web standards.

Whether this is truly more aligned with Web standards is open for debate personally I'm not into web standards enough to make my own opinion, I just answer what you asked.

like image 58
Shadow Wizard Hates Omicron Avatar answered Oct 11 '22 17:10

Shadow Wizard Hates Omicron