New Features in ASP.NET 4.0

By Joydip Kanjilal and Bhupali Khule

ASP.NET 4.0 is neither a revolutionary change nor a refactoring of the existing ASP.NET. Instead, it consists of a number of small-scale changes that allow developers to have a strong control of certain frequently used events. What makes ASP.NET 4.0 more effective than the already existing versions of ASP.NET are its rich features and powerful enhancements.

ViewState Control Enhancements

One of the major drawbacks of ASP.NET Webforms is ViewState, which can add significantly to the page size and slow performance. While initially you could set the EnableViewState property to true or false, all the controls, by default inherit and so if you set it at the control level, the behavior was inconsistent. However, with ASP.NET 4.0, the new ViewStateMode property helps to determines every control whether the ViewState should be enabled, disabled, or inherited.

Data Control Enhancements

Another interesting new enhancement in ASP.NET 4.0 is that the LayoutTemplate of the ListView data control is now optional – so you can just use the ItemTemplate of the control to display data. Here’s an example:

<asp:ListView ID="ListView1" runat="server"DataSourceID="SqlDataSource1"
ClientIDMode="Predictable">
<ItemTemplate>
Student Code:
<asp:LabelID="lblStudentCode" runat="server" Text='<%# Eval("StudentCode")%>' />
<br />
Student Name:
<asp:LabelID="lblStudentName" runat="server" Text='<%# Eval("StudentName")%>' />
<br />
</ItemTemplate>
</asp:ListView>
<asp:ListView ID="ListView1" runat="server"DataSourceID="SqlDataSource1"ClientIDMode="Predictable"><ItemTemplate>Student Code:<asp:LabelID="lblStudentCode" runat="server" Text='<%# Eval("StudentCode")%>' /><br />Student Name:<asp:LabelID="lblStudentName" runat="server" Text='<%# Eval("StudentName")%>' /><br /></ItemTemplate></asp:ListView>

In ASP.NET 3.5, you can achieve the same but you need to specify the layout template using the <layouttemplate> tag as shown below:

<asp:ListView runat="server" DataSourceID="SqlDataSource1" DataKeyNames="StudentCode" ItemContainerID="SqlDataSource1">
<layouttemplate>
<table runat="server" border="1">
<tr>
<th>StudentCode</th>
<th>StudentName</th>
</tr>
</table>
</layouttemplate>
<ItemTemplate>
<tr>
<td>
<asp:Label runat="server"
Text='<%# Eval("StudentCode") %>'/>
</td>
<td>
<asp:Label runat="server"
Text='<%# Eval("StudentName") %>'/>
</td>
<td>
</tr>
</ItemTemplate>
</asp:ListView>

Also, the RadioButtonList and the CheckBoxList controls now include a new property called RepeatLayout.

Webform Routing

Routing is a feature in ASP.NET 4.0 that enables you to use URLs to map specific resources. These URLs can then become more descriptive and user friendly. Here is an example of an URL that is descriptive:http://server/mywebapplication/Students/View/NewStudents

Reading the routing information in an ASP.NET page is as simple as the following code:

String data = Page.RouteData.Values["Item"] as string;

ASP.NET Routing was originally developed as part of ASP.NET MVC but factored out into its own assembly (System.Web.Routing) as it is useful beyond the bounds of MVC. It is used in ASP.NET Dynamic Data for example and it’s even possible to use it in webforms with a bit of work.

In ASP.NET 4.0 all the necessary components to use ASP.NET Routing are inbuilt. These include theIRouteHandler implementation (PageRouteHandler class) that serves up the right IHttpHandler to service the request and a couple of expression builders to help capture parameters from routed requests and also generate route URLs. You simply need to set up your route patterns in Application_Start() as you do for ASP.NET MVC.

For a full details see ASP.NET 4.0 Routing .

SEO Enhancements

In addition to Webforms Routing, there are a couple of minor additions to ASP.NET 4.0 to make it easier to set the Keywords and Description meta tags on a page. The page class in ASP.NET 4.0 now has two new properties, namely, Keywords and Description. These can be set either in markup code or from the code behind so that you can generate the meta tags dynamically.

Continues…

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>