Top 7 Features of ASP.NET Framework 4.0


ASP.NET 4.0 is the version of ASP.NET bundled with .NET Framework 4.0. In this article let us delve into what I think are the top 7 features of ASP.NET 4.0.

ASP.NET 4.0 application provides support to websites as well as web application projects. The default ASP.NET application provides a good starter project template with some common items which have to be built for almost all web based projects like a Master Page with a standard template, About us page, Login page, Register page, Change Password page, a default style sheet named Site.css which would already have been referred in the Master page, etc., This undoubtedly would reduce a lot of development effort. All you need to do is simply customize the predefined templates to your needs. If the developer is not interested in the default templates, ASP.NET 4.0 also provides web based projects called EmptyWebApplication and EmptyWebSite, which will not have any default items in the project except the web.config file. Fig 1.0 shows the default home page template.

Fig 1.0

Another noticeable thing would be, when you expand the Web.Config file you would find two files named Web.Debug.config and Web.Release.config. This is a new feature called Web.Config transformation, which will enable developers to maintain separate config files for different application environments. I will soon be writing an article on Web.Config transformation.

Chart Control

In my opinion the introduction of the new Chart Control in ASP.NET 4.0 makes the life of most web application developers a lot easier. In the earlier versions of ASP.NET in order to have a chart on the web page you have to download the MS charts and integrate it into the IDE which only exposed some basic chart features. For more chart features the developers had to use some third party chart controls. Now the ASP.NET chart control provides a wide range of features. In fact it also provides support for 3-D charts.
Below is the list of some of supported chart types.

  • Point

  • FastPoint

  • Bubble

  • Line

  • Column

  • Stacked Column

  • Pie

  • Pyramid

  • Etc.,

You need to simply set the data source for this chart control as you do it for a GridView and your chart is ready. Another good thing about the chart controls is that you can customize the style and appearance to a great extent. You can also provide a gradient style to your charts.

Fig 2.0 shows a sample Column Chart.

Fig 2.0

Below is the corresponding .aspx code for the above chart. Note that I have hardcoded the datapoints in order to make the example pretty simple.

<asp:Chart ID=”Chart1″ runat=”server” Width=”428px”>
               <asp:Series Name=”Series1″>
                       <asp:DataPoint XValue=”1970″ YValues=”1000″ />
                       <asp:DataPoint XValue=”1980″ YValues=”2000″ />
                       <asp:DataPoint XValue=”1990″ YValues=”3000″ />
                       <asp:DataPoint XValue=”2000″ YValues=”4000″ />
                       <asp:DataPoint XValue=”2010″ YValues=”5000″ />
               <asp:ChartArea Name=”ChartArea1″>
                   <AxisX Title=”Year” IntervalOffsetType=”Years”>
                   <AxisY Title=”City Population” IsLogarithmic=”true”>

Fig 2.1 is a sample Pie chart

Fig 2.1

Below is the code for the above chart

<asp:Chart ID=”Chart1″ runat=”server” >
               <asp:Series Name=”Series1″ ChartType=”Pie” Legend=”Legend1″>
                       <asp:DataPoint Label=”India” CustomProperties=”OriginalPointIndex=0″ YValues=”40″ />
                       <asp:DataPoint Label=”China” CustomProperties=”OriginalPointIndex=1″ YValues=”40″ />
                       <asp:DataPoint Label=”America” LabelAngle=”-50″   CustomProperties=”OriginalPointIndex=2″ YValues=”10″ />
                       <asp:DataPoint Label=”Australia” LabelAngle=”-10″  CustomProperties=”OriginalPointIndex=3″ YValues=”10″ />
               <asp:ChartArea Name=”ChartArea1″>
               <asp:Legend Name=”Legend1″>
               <asp:Title Name=”Population Chart” Text=”Population Chart”>

ClientIDMode for controls

In earlier versions of the ASP.NET Framework if you place a control inside a container control like a Template column of a GridView, Template of a Login Control, etc., at runtime the IDs of those controls will be replaced with random unique IDs generated by ASP.NET itself. This was a big and long standing problem for the developers to access the control on the server side using Page.FindControl(“controlid”) as well as in JavaScript using document.getElementbyId(“controlid”). In simple terms the control ids generated at runtime were not predictable.

But .NET developers no longer find themselves in such situation because in ASP.NET 4.0 there is a property called ClientIDMode for all the controls. This has provided good control over the ID generated for the content controls during runtime.

The types of ClientIDModes available are:

  1. AutoID – This is the same random way as it uses to happen in the earlier versions of ASP.NET.
  2. Static – The ID of the control will not change at the runtime. This is pretty handy setting if the control is being used in the container or in the child pages and needs to be accessed on the client scripts.
  3. Predictable – For the controls like a textbox in a GridView template column Static mode will not be useful because of the repeating rows of the GridView. In such scenarios Predictable mode comes in handy where the developer can provide a predictable value say a primary key of the GridViewRow using the ClientIDRowSuffix property. This will append the predictable unique value as suffix to the actual control id. For example if the actual control id in the TemplateColumn is txtBox and the ClientIDRowSuffix is the GridViewRowIndex then the generated IDs during runtime for row1 textbox ID will be GridView1_txtBox_1, for row2 it will be GridView1_txtBox_2 and so on.
  4. Inherit – This will inherit the ClientIDMode value from its parent control.

You don’t have to provide the ClientIDMode for each and every control rather you could specify it at the page level in the page directive.

<%@ Master Language=”C#” ClientIDMode=”Predictable” AutoEventWireup=”true” CodeBehind=”Site.master.cs” Inherits=”MyWebApplication.SiteMaster” %>

Or it could also be provided at the application level using the web.config specification as shown below.
     <pages clientIDMode=”Predictable”></pages>

Note that the ClientIDMode specified at the control level will override the above settings in the page directive and web.config.

More by Author

Must Read