.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

New Features of ASP.NET 4.0

Posted By:Virendra Dugar       Posted Date: October 19, 2009    Points: 25    Category: ASP.NET    URL: http://www.dotnetspark.com  


As we all know, ASP.NET 4.0 is around the corner and it will be released soon. This article gives you some brief info regarding the enhancement and feature of ASP.NET 4.0. This article explains these features/Enhancements

  • ViewState Mode Property
  • ClientID Mode feature
  • No need to type runat="server" 
  • ListView Enhancement
  • FormView Enhancement

ViewState Mode Property

ViewState is a very misunderstood animal. ViewState is a headache for the programmers. Programmers leave it enable for all the controls even if there is no need to persist their value. Right use of ViewState can increase the performance of the page drastically.

Before I discuss about this new property, let's come back to the current era of ASP.NET 3.5 or previous version of .NET. What if you turn off ViewState at page level and make it on at control level? Ask yourself, is it possible with previous versions of .NET (upto 3.5)? Sorry but there is a bad news that it's not possible. But there is a good news as well. You can achieve this with new version of ASP.NET that is 4.0.

ASP.NET 4.0 comes with new and cool property ViewStateMode. It has 3 possible values.

  • Enabled : This turns on the ViewState for the control.

  • Disabled : This turns off the ViewState for the control.

  • Inherit : Takes the value from the parent and set it accordingly. If it has been set to Disabled at Page level and for textbox you set ViewStateMode = "Inherit" then it will disable the ViewState for the textbox.

The main difference between EnableViewState and ViewStateMode property is, if EnableViewState property is set to disabled at parent level, there is no way of making viewstate enable at control level, But this is possible with this new property :ViewStateMode.

ClientID Mode Feature

As we know, When Master Page is used then the ID of controls gets changes when page is in running state. As for example for textBox named "txtname" the clientID becomes "ctl00_MasterPageBody_ctl01_txtName". (Well, it's depeneds upon the master page and content place holder name).

ASP.NET 4.0 has introduced a new property for ASP.NET control named ClientIDMode. Once you set the ClientIDMode property for a control, the ClientID is modified accordingly.

This property has 4 possible values

  1. Static
  2. Legacy : Default is Legacy if it's not set.
  3. Inherit
  4. Predictable

To know more about this feature and these properties, read this nice article.

No need to type runat="server"

If you are using Visual Studio 2005 or 2008, for every asp.net or Html control, you need to explicity write runat="server" attribute. Sometimes I really wonder, why I have to write this attribute for every control as most of time I want to access controls on server side. Is n't is tedious task? It should be added automatically. But it's not possible with Visual Studio 2005 or 2008.

Well, we have a good news now. Now there is no need to type runat="server". It does not mean that It has been removed. Nope.. it's get added automatically in VS 2010. Wow.. amazing..

In VS 2010, Microsoft has added hundereds of new code snippest for HTML, JavaScript and for ASPX. If you want to place a textbox on the page, type tb and press Tab. Wow. You will see something like this..

Type req and press Tab. Boom.

There are lots of other code snippest almost for every control. Even for HTML tag also like table. Is n't is cool?

List View Control Enhancement

The ListView control, which was introduced in ASP.NET 3.5, has all the functionality of the GridView control while giving you complete control over the output. This control has been made easier to use in ASP.NET 4.0. The earlier version of the control required that you specify a layout template that contained a server control with a known ID. The following markup shows a typical example of how to use the ListView control in ASP.NET 3.5.


      <% Eval("LastName")%>

In ASP.NET 4.0, the ListView control does not require a layout template. The markup shown in the previous example can be replaced with the following markup:

      <% Eval("LastName")%>

Form View Control Enhancement

The FormView control is data-bound control that is nothing but a templated version of DetailsView control is designed to give you full control over the rendered markup. Bydefault, FormView control gets rendered as HTML table. Consider this example :

      Content goes here!

This gets rendered like :


         Content goes here!

ASP.NET 4.0 comes with new property RenderTable which lets you specify whether the FormView control renders using a table. This is how you specify it..

<asp:FormView ID="FormView1"runat="server" RenderTable="false">
If this property is used with previous example then the output will be without table, tr and td tag:

Content goes here!

This enhancement can make it easier to style the content of the control with CSS, because no unexpected tags are rendered by the control..



There are lot more things in .NET 4.0. If you know more kindly post in your comments.

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend