ASP.net 4.0 features


This article contains information about some of the key features in the .NET Framework version 4 which helps the developers to do the coding more efficiently. There are many more features of asp.net framework 4.0 available which I will explain in my next article.

Features of .NET Framework 4.0



Below are some of the new features that .net framework 4.0 provides from development point of view.

1. Better Viewstate management: When we use viewstate to store large amount of data, it causes heavy performance penalty. To tackle this problem ASP.NET 4 introduces a new property called ViewStateMode in the Web controls with the help of which you can disable view state by default and then enable it only for the controls that require it in the page. This property has three values: Enable, Disable, and Inherit.
You can also set the ViewStateMode at the page level:

<%@ Page Title="MyPage" Language="C#" MasterPageFile="~/Site.master"
AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="_OutputCacheDemo._Default" ViewStateMode="Disabled" %>


2. Session State Management: People generally store objects in session state during web application development. As you know the objects stored in the session state must be serializable, if object is heavy the size of serialized data becomes quite large. To solve this issue ASP.NET 4 introduces a new compression option for both kinds of out-of-process session-state management techniques. When the compressionEnabled configuration option is set to true, ASP.NET will compress (and decompress) serialized session state by using the .NET Framework System.IO.Compression.GZipStream class.


<sessionState mode="SQLServer" sqlConnectionString="data source=dbservername;
Initial Catalog=aspnetstate" allowCustomSqlDatabase="true" compressionEnabled="true"/>


3. Setting Client Id's: When we build web applications, its common practice to use JavaScript/Ajax. Until ASP.NET 4 we get the id attribute from the ClientID property which is concatenate with the naming container (if any) with the ID, and in the case of data controls, a prefix and a sequential number gets added. The IDs of controls that get generated are unique but the algorithm has resulted in control IDs that were not predictable. Hence difficult to reference in client script. This occurs generally when we're using master pages.

We generally get the Client id's for earlier version as below:


var mybtn = document.getElementById ("<% =Button1.ClientID %>");


ASP.NET 4 introduces new ClientIDMode property that specifies how the client ID is generated for controls. You can set the ClientIDMode property for any control, including for the page. Possible settings are the following:

AutoID. This is equivalent to the earlier generated ClientId property values(Previous version of asp.net)

Static. This specifies that the ClientID value will be the same as the ID without concatenating the IDs of parent naming containers.

Predictable. This option is useful in data control that uses repeating templates. It concatenates the ID properties of the control's naming containers, but generated ClientID values do not contain strings like "ctlxxx". This setting works in conjunction with the ClientIDRowSuffix property of the control. You set the ClientIDRowSuffix property to the name of a data field, and the value of that field is used as the suffix for the generated ClientID value. Typically you would use the primary key of a data record as the ClientIDRowSuffix value.

Inherit. This setting is the default behavior for controls; it specifies that a control's ID generation is the same as its parent.


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: