New Features of ASP.NET 4.0

Virendradugar
Posted by in ASP.NET category on for Beginner level | Views : 8266 red flag

This articles gives a brief info on some of the new features and enhancement of ASP.NET 4.0
Introduction
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
I have already post articles about ViewState Mode Property and No need to type runat="server" but I have included these article in this to put all together about ASP.NET 4.0.

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..

<asp:TextBox ID="TextBox1" runat="server"/>

Type req and press Tab. Boom…

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="errormessage"></asp:RequiredFieldValidator>

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.

<asp:ListView ID="ListView1" runat="server">
   <LayoutTemplate>
      <asp:PlaceHolder ID="ItemPlaceHolder" runat="server"></asp:PlaceHolder>
   </LayoutTemplate>
   <ItemTemplate>
      <% Eval("LastName")%>
   </ItemTemplate>
</asp:ListView>

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:

<asp:ListView ID="ListView1" runat="server">
   <ItemTemplate>
      <% Eval("LastName")%>
   </ItemTemplate>
</asp:ListView>
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 :

<asp:FormView ID="FormView1" runat="server">
<ItemTemplate>
      Content goes here!
</ItemTemplate>
</asp:FormView>

This gets rendered like :

<table cellspacing="0" border="0" id="FormView1" style="border-collapse:collapse;">
<tr>
   <td colspan="2">
         Content goes here!
   </td>
</tr>
</table>

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..

References
 

Conclusion

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

Page copy protected against web site content infringement by Copyscape

About the Author

Virendradugar
Full Name: Virendra Dugar
Member Level: Silver
Member Status: Member,MVP
Member Since: 8/11/2009 4:14:05 AM
Country: India

http://jquerybyexample.blogspot.com
Virendra Dugar is experienced Senior Software Developer with over 5 years of hands-on experience working with Microsoft .NET technology (ASP.NET, C#, VB.NET,SQL Server). He is always keen to learn new technology. He holds a Master's Degree in Computer Application & Information technology from Gujarat University in india.In free time, he loves to listen music, read books, play games and do blogging etc. Visit his blogs : http://jquerybyexample.blogspot.com

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)