jump to navigation

Hidden Div elements in ASP.Net 4.0 April 5, 2010

Posted by fofo in ASP.NET 4.0, Visual Studio 2010.
trackback

This is a very short post for a new feature that ships with VS 2010 and ASP.Net 4.0.

It is about the hidden fields in ASP.Net 4.0. We do know 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>.

So if you create a simple asp.net application with VS 2008 and .Net 3.5, run it, and view the source code from the browser,

you would see something like that

<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=”/wEPDwUKLTQ0NTA1MjAxMmRkjIozh8I5q9vNjFXLeK/1IBsUwBM=” />
</div>

Sometimes if you style your div elements in your external css file, those rules that apply for all div elementsin your code, will apply for that <div> that surrounds the hidden field elements that deal with the viewstate.

Sometimes you can end up having a result in your browser window that is different from what you expected. The guilty part for that outcome can be the styling of those div tags that surround viewstate.

We have a small but very welcome change in ASP.Net 4.0

If you create a simple asp.net application with VS 2010 and view the source code after you run it, you will see something like this

<div class=”aspNetHidden”>
<input type=”hidden” name=”__VIEWSTATE” id=”__VIEWSTATE” value=”/wEPDwUJNzM3NjE2MDI3ZGRgQNiFxlXngQrLz2ewgBmti+Ee0T+BGCrLcGwY5QJnmQ==” />
</div>

As we can clearly see, ASP.NET 4 renders the div element for hidden fields with a CSS class.

In that way we can differentiate the hidden fields div from others.

Hope it helps!!!

Comments»

1. Expats find their havens in Davao - September 17, 2012

[…] Hidden Div elements in ASP.Net 4.0 « DOT NET RULES […]

2. Shahrukhkhan Pathan - March 12, 2013

can you please tell me that how to avoid this aspnethidden div????????????????


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: