Why does <form runat="server"> render <div> around viewstate hidden variable?

I can't figure out why asp.net thinks it needs to render a div around the viewstate hidden variable, or if there's any way to get it to stop doing it:

<form name="aspnetForm" method="post" action="default.aspx" id="aspnetForm" class="mainform">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTEwMDUyNjYzMjhkZA1/6gmEk+w4wUiViNwm8AqBxBo1" />

It screws up attempts to style pages in certain ways, and since there's no way to put an id or class on it, I can't style it in css (at least w/o the risk of screwing up any other divs I have within the form and having to override them.

Is there some way to overcome this?

Also, for what it's worth, that hidden input element was rendered even if I disabled viewstate on the master page, the aspx page and the form element itself. I couldn't get rid of the rendering even by trying to completely disable viewstate.

Any help out there?




10/28/2006 2:58:16 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

7 Replies

Similar Articles

[PageSpeed] 2
Get it on Google Play
Get it on Apple App Store

Hi Donnie ViewState can become a pritty indepth topic so forgive me if this post isnt all that helpful.......May I ask why you are disabiling ViewState?, You need to be careful when doing this there are a number of articles that cover this topic I'll include them at the end of this post..

First the div tag is an autogenerated thing its a blank input and should not cause any styling problems, it is strange to hear that it would, I've never incountered any styling problems with this blank DIV in any of my projects, and I may be wrong about this but even if you disable viewstate on a page you will still get the viewstate hidden field it just doesnt hold any data, I think you need to disable it from the Web.Config or Machine.Config to remove this but that may be a security concern......Sorry I know this doesnt help much but I've read all the following articles and they can help you understand much better then I can why viewstate does what it does......I'm currently struggling with my viewstate for the fact I cant save textbox values of dynamically created textbox's through postbacks....





Internet Marketing Center
Agloco | Own The Internet
10/28/2006 7:21:26 AM

is thid div cause  any problem to u ...

i thinks aspnet add it to avoid rendering  problems ...

by the way i think its depend on the client browser   ....

in my IE6 no div rendered or at least on my computer nevertheless im turning on Viewstate 

i think  also in browser that dont support  <div> thins will rendered  in different way  ....

again ... what is the problem  with it at all ...

i think because no height or width properties and no visible elements (since contains only hidden field ) so it will not make any positioning proplems ..

it will not take any space in the rendered page .. !!!


Anas Ghanem.

Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!

10/28/2006 9:21:27 AM
Actually I think you are right about the browser support I've only tested my pages on IE6 before and dont have a problem so if your experining a design issue when testing it in another browser, that browser very well might not support the DIV or it may support it in a different manner then IE6 does
Internet Marketing Center
Agloco | Own The Internet
10/28/2006 9:28:02 AM

First, I was only disabling viewstate as a means to test getting rid of that div. Normally I wouldn't do that, but if I did, I'd expect that disabling it would get rid of that altogether. In this case, I'm developing more of a site, not an app. I wouldn't need viewstate. But since it didn't get rid of the div, I re-enabled it.

Second, the reason it can mess with appearance is due to CSS inheritance. It can implicitly get styles from other things defined in the CSS. The anomaly I was seeing was in IE 6; and naturally Firefox behaved correctly. I have been able to work around my problems by assigning margin and padding to the form (since it can have a class assigned to it) and some other hoops I shouldn't have to jump through.

But I'll stand by my statement that if asp.net is going to render a div, it needs to give us an easy hook via which to assign it an ID, a class, or something.



10/28/2006 1:41:31 PM

hi ...

i want to know where this div come from  ... really

hey ... on what browser this happended(is it just on IE6 only )

did u try firefox .... (i really want to know where it comes from ..)

is it from your config or from your browser ???

do u use master pages ? asp2.0 ?

 tell me




Anas Ghanem.

Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!

10/28/2006 3:06:50 PM

You can see the div in the message that started this thread - it's just after the form element. To your other questions:

- I see it in both IE and Firefox

- ASP.NET 2.0

- The form element is within a master page, the page being rendered is essentially empty

- Nothing special in my config

- Stock VS 2005 web *site* project that I just started - hardly anything in it yet, and no server controls other than the form runat="server"


Hope that helps,



10/28/2006 3:34:52 PM


i think there is no way do avoid this

see this thread for more info




good luck


Anas Ghanem.

Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!

10/29/2006 6:17:08 AM

Similar Artilces:

What if I remove <form id="form1" runat="server"></form>
If I am creating an aspx page, which does not need to be a form, i.e. no input is taken from the user, do I need to encapsulate the whole page with in  <form1 runat="server">   What are the implications of removing the form? I realize there will be no viewstate, and again, I won't be able to accept user input, but will everything else work as expected? It seems to be so far, I've just not seen ANY examples where the form tag has been removed. Thanks, Darragh You need the server-side form tag if you are going to have server-side controls on the form.RyanRyan Olshan...

can I delete <form id="form1" runat="server"> and </form>
Hi: Our website is written by using simple html code, one of the page has some virtual shopping cart code with <form> ....</form>, (for example here: http://www.centercoin.com/coin_supplies/coin_collecting_starter_set.htm ), if I have 10 products, I will have 10 of <from> ...</form> in this page, that is ok. Now, I am trying to redesign the website using asp.net2.0, I notice all the asp page will automatically create a <form id="form1" runat="server"> ...</form>, such as: <html xmlns="http://www.w3.org/19...

<form id="form" runat="server">
hey i have a very similar problem to this thread http://forums.asp.net/thread/1440587.aspx"Control 'ctl00_ContentPlaceHolder1_Login1' of type 'Login' must be placed inside a form tag with runat=server. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Web.HttpException: Control 'ctl00_ContentPlaceHolder1_Login1' of type 'Login' must be placed inside a form tag with r...

Programmatic equivalent of <form runat="server"> </from>
When designing an ASPX page, WebControls must be contained into a tag <form runat="server"></form>.I am trying to achieve the same effect but in a programmatic manner within a .Net library (using HttpHandlers).Does anyone has an idea how to do that?Thanks in advance,Joann├ĘsLokad.com, time-series forecasting  Actually, I might have succeeded to solve this issue, but I am not too sure if it's the "right" way to do it.public class MyPage : Page { protected override void CreateChildControls() { HtmlForm htmlForm = new HtmlForm(); Controls.Add(htmlF...

Error on <form enctype="multipart/form-data" runat="server">
Hi to all... i have this problem which occured when i was uploading a picture into the SQL 2000. i am using VB script and Microsoft Visual Studio 2005... the error on"<pages enableEventValidation="true"/>"... can anyone help me??  i am using a master template for my webpage... everything work jus fine before i insert this "<form enctype="multipart/form-data" runat="server">" at the top of the page after "<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server&...

"<table></table>" and "<frameset><frame></frame></frameset>" in perl/tk
Dear my friends... Anybody would be so kind telling me what is similar in perl/tk to arrange the location of a form written in perl/tk? I want a nice look for my perl/tk application. Somewhat like this below: 1. Name : <place to type-in> 2. Address : <place to type-in> 3. Telephone : <place to type-in> I have made the main menu of my application with "Menubutton". And I want if the user click on the menu that what the user see is only the aimed application displayed on the determined area (under the main menu) but the menu has no change in po...

I've placed <forms loginUrl="home.aspx"></forms> in web.config and now all users that log in go to default.aspx
I've placed <forms loginUrl="home.aspx"></forms> in web.config and now all users that log in go to default.aspx.        <authentication mode="Forms">        <forms loginUrl="home.aspx"></forms>      </authentication>What attribute I should add, to make the user stay on the same page. Btw when I remove  <forms loginUrl="home.aspx"></forms>, users stay on the same page after login.Thanks. try one of these.....

<form id="form3" runat="server">
i am really confused about the <form id="form3" runat="server">  error i receive the thing is LoginStatus1 andCreateUserWizard1both require their components to run at the server. however only one form server is allowed in the document. i receive this error message in the browser, and vice versa for the other component.Server Error in '/vwd test/Techworld' Application. A page can have only one server-side Form tag. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for mor...

<sessionState timeout="x"/> vs <forms timeout="y"/>
How to configure web app: x=y x>y x<y ?...

Code Behind or "<script runat="server">...code...</script>"?
Hi, I've just started learning asp.net after a number of years with VB. A lot of the examples I've been researching have placed the VB code directly onto the .aspx web page with a "<script runat="server">...code...</script>" format rather than placing the code in a "code behind" .vb page. Is there any reason for this other than the fact that you can place all the relevant code onto one example? From a .Net Studio point of view, it's seems to be far easier to use Code Behind, as one can take advantage of the "Auto Complete" features th...

<ypbp:CategoryTree id="categoryTree" runat="server"></ypbp:CategoryTree>
Hi All, I hope you can help a very confused beginner. I am writing a site that has a navigation tree configured from a database. I wanted to create a reusable piece of code that "draws" the navigation tree based on a request parameter that indicates to the code how to draw the tree. For example, the first time the page loads it will draw all the top level menu items only, and when a user clicks on one of those options it would draw all the top items and also the children of the item just clicked on etc... I want this to be reusable because I am writing an admin backend to the website as we...

MasterPage does not work with <form id="Form1" runat="Server">
When I add my masterpage to my content page I am getting - A page can have only one server-side Form tag. Content page: (VB.Net)1 <%@ Page language="VB" Inherits="dotForumPostReply.addReply" EnableEventValidation="False" 2 CodePage="1252" MasterPageFile="masterpage.master" %> 3 <%@ MasterType VirtualPath="masterpage.master" %> 4 <%@ Register NameSpace="OSS" TagPrefix="OSS" %> 5 <%@ import namespace="System" %> 6 <%@ import namespace="System.Data&...

Can't use "defaultbutton" in <form></form> tag in login control page.
I have a login control and I tried to set the default button as the submit button within my form tag in the login page.But, I am getting the following error.Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster. I already generated the machine key.Any clue! hi robin, Please try this fix if.. add the below given code into your web.config or the file that you are executing and see if your issue gets...

How to strip a string of <html>, ,</html>, <body>, </body>, <form ... >, </form> tags?
I have stream which is the HTML input of a page. Now I want to use only that part of this page, that is within <form .....> and </form> tags, and excluding these tags.How would I go about stripping <html>, ,</html>, <body>, </body>, <form ... >, </form>, <head> and </head> tags? I have to make sure that <head ...javascript..> and its corresponding </head> tags are not stripped in this process.sun21170    Wait... you said you wanted to strip the head tags, and you're also saying you need to NOT strip the ...

Web resources about - Why does <form runat="server"> render <div> around viewstate hidden variable? - asp.net.web-forms

Resources last updated: 11/22/2015 7:07:00 AM