Features in ASP.NET 4.0

ASP.NET 4.0 includes enhancements in many areas. This article is an overview of the new and major improvements that are included in ASP.NET 4.0.
Output Caching
Since  ASP.NET 1.0, output caching has is being used to store the generated output of pages and controls. On subsequent requests, ASP.NET can serve the HTML content more quickly from memory instead of generating the output from scratch. However, this approach has the limitation that the generated output always has to be stored in memory and if the website experiences heavy traffic the memory requirements can be drastic.
ASP.NET improves output caching by providing output-cache providers. Output-cache providers can use any storage medium to store the generated output. This storage medium can vary from local or remote disks to cache engines.
A new cache provider can be created deriving from OutPutCacheProvider class. We can configure the Cache provider in the Web.config file in the new provider's subsection of the outputCache element.
We can use the different providers for different controls using the providerName attribute of the Output cache element.
  1. <%@ OutputCache providerName="MyCache" %> 
Redirecting page to a new link
The website content is moved during the lifetime of the web application from one URL to another. This was handled by using the Redirect method to redirect to the new URL. One disadvantage with this method is that the Redirect method results in extra roundtrip to the server.
ASP.NET 4 introduces the RedirectPermanent method.
Search engines can store the new URL associated with the content removing the need to use the Redirect method for moved content. 
This method can be used to move to the new link:
Enabling Viewstate on Control basis. 
In the previous versions of ASP.NET, we can't turn off the viewstate for the entire page and then unable it for some of the controls that need it. We can do so in ASP.NET 4.0. This is more convenient than disabling the viewstate on control by basis. You can set the ViewStateMode for the page to false and then enable it for individual controls.
Row Selection in GridView and ListView
In previous versions of ASP.NET in Gridview and Listview rowselection was on the basis of RowIndex. If we selected the nth row on a page and moved to another page then the nth row was selected on the moved page as well.
It is more desirable not to select any row in the moved page and when the user comes back on the original page he should see the nth row selected. ASP.NET 4 provides persisted selection in which row selection is based on the data key. We enable persisted selection by using the PersistedSelection attribute to "true" in the GridView Control.
Session State Compression
There are two options to store session state data out of process one is session state provider that stores data in session state server and the second is session state provider that stores data in a Microsoft SQL Server database. The size of the serialized data stored in the session state server and SQL Server can be too large. In ASP.NET 4 there is a compression option to store the serialized data. This option can be enabled using compressionEnabled attribute in the Session State element.
  1. <sessionState  
  2. mode="SqlServer"  
  3. sqlConnectionString="data source=myserver;Initial Catalog=aspnetstate"  
  4. compressionEnabled="true"  
  5. /> 
ClientIDMode Property for generated ClientID
Every asp.net control is rendered as an HTML element and a corresponding ClientId is generated for it. If we want to reference the generated HTML element in javascript we must know the Id attribute of the generated element. The ID attribute in HTML that is rendered for Web server controls is generated based on the ClientID property of the control. 
Until ASP.NET 4, we do not have much control over the generated Id of the Control. The new ClientIDMode property lets you specify more precisely how the client ID is generated for controls.
Possible settings for ClientIDMode are the following:
  • AutoID - Generated ClientID is similar to earlier versions of ASP.NET.Difficult to predict generated Id values.
  • Static - This specifies that the ClientID value will be the same as the ID. For example, if our label control has id HeaderLabel then the ClientId will also have a value of HeaderLabel
  • Predictable - This setting is used mostly in controls that are inside Data Bound Controls. The  ClinetId value is generated by concatenating the ClinetId value of the parent naming container with the ID value of the control. This setting  works in conjunction with the ClientIDRowSuffix property
    If specified the value of the data field specified in the ClientIDRowSuffix property is added at the end.
    For instance, if we have StudentName Label inside ListView1  Student Name labels ClinetIDMode is set to Predictable and ClientIDRowSuffix is set to "ID" then StudentName labels' generated client id's will be as :
    ListView1_ StudentName _1
    ListView1_ StudentName _2
    ListView1_ StudentName _3
    ListView1_ StudentName _4
  • Inherit - The control inherits the ClientIDMode setting of its parent control. This is the default value for the control
ListView Control 
Until ASP.NET 3.5 ListView control required ItemTemplate and LayoutTemplate. ItemTemplate specifies the markup for each item bound to the ListView while LayoutTemplate defines just the enclosing markup for the items in the ListView.
The LayoutTemplate serves no purpose but to specify where the markup of ItemTemplate should appear.
In ASP.NET 4.0 we don't need the LayoutTemplate in ListView, the ItemTemplate is the only required template.
So instead of the following markup :
  1. <asp:ListView ID="ListView1" runat="server" ...>  
  2.    <LayoutTemplate>  
  3.       <asp:PlaceHolder runat="server" ID="itemPlaceHolder" />  
  4.    </LayoutTemplate>  
  5.    <ItemTemplate>  
  6.       ...  
  7.    </ItemTemplate>  
  8. </asp:ListView> 
We just need 
  1. <asp:ListView ID="ListView1" runat="server" ...>  
  2.    <LayoutTemplate>  
  3.       <asp:PlaceHolder runat="server" ID="itemPlaceHolder" />  
  4.    </LayoutTemplate>  
  5.    <ItemTemplate>  
  6.       ...  
  7.    </ItemTemplate>  
  8. </asp:ListView>