spankmaster79 spankmaster79 - 1 month ago 18
ASP.NET (C#) Question

aspnethidden CSS class missing in ASP webforms application

this might be simple, but I can't find information about it.

Why is the aspnethidden CSS class missing from the div's around hidden form fields in my development environment and not on the production environment? It looks like this:

<div>
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="..." />
<input type="hidden" name="__VIEWSTATEENCRYPTED" id="__VIEWSTATEENCRYPTED" value="" />
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="..." />
</div>


instead of this:

<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="..." />
<input type="hidden" name="__VIEWSTATEENCRYPTED" id="__VIEWSTATEENCRYPTED" value="" />
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="..." />
</div>


The server and my dev machine are running on .NET Framework 4.6.1 and IIS is configured to use the .NET CLR 4.0 in the application pool.

I'm just curious to know why this is missing on my Windows 10 Dev machine.

Answer

The one which you are observing is a New feature .It is about the hidden fields in ASP.Net 4.0.

You probably might aware that ASP.Net is using hidden fields as a state control mechanism. It is used to preserve Viewstate and Control state.

They are usually included in a div element, <div></div>.

I have created a sample asp.net application in VS2010 and .Net 3.5

when i see my view source i'm able to see something like this

<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/rxyklmnLTQ0NTA1Mstupvmjk8I5q9vNjFXLeK/1IBsUwBM=" />
</div>

when you apply any css rules for div elements in your external css file, those rules that apply for all div elements in your code, will apply for that <div> that surrounds the hidden field elements that dealing with the viewstate.

When you create the application with the Asp.net 4.0 will render with CSS class around div

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

Based on My Research here are some Souces which will elaborate more

  1. how-to-handle-the-div-tag-around-asp.net-hidden-inputs.aspx
  2. ASP-NET-SEO-around-VIEWSTATE
  3. hidden div elements in asp.net 4.0

Update

In your dev machine , you might have set the

controlRenderingCompatibilityVersion="3.5" 

so that is the reason you are unable to see that class aspNetHidden in your dev machine as that feature was introduced in Asp.net 4.0

Comments