History of ECMAScript and JavaScript

September 28, 2015 Leave a comment

Hello folks ,

Nowadays “JavaScript” is used anywhere , instead of being only the client side , cross browser scripting language it has been evolved as a backend language as well (Node.js) and soon its going to handle the hardware as well http://www.espruino.com/ .

Though we use JavaScript every now and then , directly , indirectly (with Jquery) now it is part of every web developers work life , but very few know the history of JavaScript , how it has been evolving , who specifies the standards for JavaScript which made it multi browser compatible.

Lets go back in the 90s to know this

JavaScript is invented by Brendan Eich in ten days in 1995 while working with NetScape  (Now Mozilla) , It was initially named Mocha, later LiveScript, and finally JavaScript.

The change of name from LiveScript to JavaScript roughly coincided with Netscape adding support for Java technology in its Netscape Navigator web browser. The final choice of name caused confusion, giving the impression that the language was a spin-off of the Java programming language, and the choice has been characterized as a marketing ploy by Netscape to give JavaScript the cachet of what was then the hot new web programming language.

Soon later in 1996 , Microsoft introduced VBScript and JScript in the market , But the different standards between NetScape’s Javascript and Microsoft’s JScript
made it difficult for the developers to make the website compatible in both the browsers.

Declaration of ECMA script :

In November 1996, Netscape announced that it had submitted JavaScript to ECMA International for consideration as an industry standard, and subsequent work resulted in the standardized version named ECMAScript.

In June 1997, ECMA International published the first edition of the ECMA-262 specification.

In June 1998, some modifications were made to adapt it to the ISO/IEC-16262 standard, and the second edition was released. The third edition of ECMA-262 was published on December 1999.

Development of the fourth edition of the ECMAScript standard was never completed.The fifth edition was released in December 2009. The current edition of the ECMAScript standard is 6, released in June 2015.
All Browsers javascript compilers (called ECMAScript engines) follow the ECMA script as the standard which made javascript compatible with most of the browsers those follow ECMAScript.

The evolution we have been seeing in the javascript is done by ECMA script with 6 releases till date.

List of ECMA Script features browser supporting http://kangax.github.io/compat-table/es5/

Regards ,

Ganesh Divekar

ASP.NET WEB API – What and Why

Hi Friends,

Microsoft has introduced a helpful framework with ASP.NET MVC4 called WEB API for building the http based services.

In this article we will cover following points about this new framework



ASP.net Web API is an api which helps in creating the http based client and server endpoints on top of the ASP.net framework.

The Client side http based programming model has been built in to the System.net and the server side http based programming model has been built in to the WCF.

The First version of WCF did not support the Http based services.
It strongly supported the traditional Soap based service endpoints which really lack in the many other features in http like caching , compression etc.

With the release of the .NET Framework 3.5 in November 2007, Microsoft released the feature to create the simple http based endpoints but it was again more embedded in the WCF.

So Microsoft WCF team has decided to come up with the framework which is completely used for the http based services ,
As ASP.NET team is more engage in the web / http  work , routing , html Microsoft has decided to merge this framework with the ASP.Net
and introduced WEB API with the ASP.NET MVC 4 release.


If we are implementing an application whether html 5 or mobile , they need services for accessing data or to artifact the system.
In the modern programming land scape services should be created by keeping wide range of clients in mind.

Most of the applications are accessing data as JSON using HTTP based services which is going to be a trend than accessing data from traditional Soap services.


This article is the summary of the video by Jon Flander on the pluralsight website.

please refer http://www.asp.net/web-api for details of web api.



Ganesh Divekar

ASP.NET # MVC # 21 Telerik Grid with checkboxes problem – Grid does not maintain the state of the checkboxes on changing page index

Telerik provides the best UI controls for the ASP.NET MVC application development.
Especially the Telerik Grid is used often in the web development.

However Checkbox column functionality of Telerik Grid does not maintain the state of the checkboxes on the page index changing event.
If user selects check boxes on the first page and then goes to the other and the checks made on the first page disappears.

Solution for above problem is explained with the help of following example by using the jQuery live event and the JavaScript arrays:

In this example we have a grid with checkboxes that is bound to the Model class name Order.

The order class has three properties OrderId,OrderName and IsChecked.                  IsChecked property is a Boolean  flag to see whether order is previously checked or not.

Controller code contains _ChckBoxesAjax method with a GridAction attribute that returns the IEnumerable list of type Order class.

Code on Controller
  1. [GridAction]
  2.       public ActionResult _CheckBoxesAjax()
  3.       {
  4.           List<Order> lstOrder = new List<Order>();
  6.           lstOrder.Add(new Order { OrderId = 1, OrderName = "Order 1", IsChecked = false });
  7.           lstOrder.Add(new Order { OrderId = 2, OrderName = "Order 1", IsChecked = false });
  8.           lstOrder.Add(new Order { OrderId = 3, OrderName = "Order 2", IsChecked = true });
  9.           lstOrder.Add(new Order { OrderId = 4, OrderName = "Order 3", IsChecked = false });
  10.           lstOrder.Add(new Order { OrderId = 5, OrderName = "Order 4", IsChecked = false });
  11.           lstOrder.Add(new Order { OrderId = 6, OrderName = "Order 5", IsChecked = false });
  12.           lstOrder.Add(new Order { OrderId = 7, OrderName = "Order 6", IsChecked = true });
  13.           lstOrder.Add(new Order { OrderId = 8, OrderName = "Order 7", IsChecked = false });
  14.           lstOrder.Add(new Order { OrderId = 9, OrderName = "Order 8", IsChecked = false });
  15.           lstOrder.Add(new Order { OrderId = 10, OrderName = "Order 9", IsChecked = false });
  16.           lstOrder.Add(new Order { OrderId = 11, OrderName = "Order 10", IsChecked = true });
  17.           lstOrder.Add(new Order { OrderId = 12, OrderName = "Order 11", IsChecked = false });            
  18.           return View(new GridModel(lstOrder.AsEnumerable()));
  19.       }
  21.   }
  23.   public class Order
  24.   {
  25.       public int OrderId { get; set; }
  26.       public string OrderName { get; set; }
  27.       public bool IsChecked { get; set; }
  29.   }


The client side code is written in the View file.There are two JavaScript function

1. RegisterLiveEventForCheckBoxes – This method should be called on the document.ready    method of the page which has the Grid on it.

2.OnCheckBoxGridDataBound – This method will be called on the OnDataBound event of the grid.

View and Client side code
  1. @{
  2.     ViewBag.Title = "_CheckBoxesAjax";
  3.     Layout = "~/Views/Shared/_Layout.cshtml";
  4. }
  5. <script type="text/javascript">
  7.     var selectedIds;
  8.     var deselectedIds;
  9.     $(document).ready(function () {
  10.         RegisterLiveEventForCheckBoxes();
  12.     });
  13.     function RegisterLiveEventForCheckBoxes() {    
  14.         selectedIds = []; deselectedIds = [];
  15.         $('#OrderId:checkbox').die();
  16.         $('#OrderId:checkbox').live('click', function (e) {
  17.             var $check = $(this);
  18.             if ($check.is(':checked')) {
  20.                 if ($.inArray($(this).val(), deselectedIds) > -1) {
  21.                     deselectedIds = jQuery.grep(deselectedIds, function (value) {
  22.                         return value != $check.val();
  23.                     });
  24.                 }
  25.                 selectedIds.push($check.val());
  26.             }
  27.             else {
  29.                 if ($.inArray($(this).val(), selectedIds) > -1) {
  30.                     selectedIds = jQuery.grep(selectedIds, function (value) {
  31.                         return value != $check.val();
  32.                     });
  33.                 }
  35.                 deselectedIds.push($check.val());
  36.             }
  37.         });
  38.     }
  40.     function OnCheckBoxGridDataBound(e) {
  42.         $('input:checkbox[id*=OrderId]:checked').each(function () {
  43.             if ($.inArray($(this).val(), selectedIds) < 0) {
  44.                 selectedIds.push($(this).val());
  45.             }
  46.         });
  47.         selectedIds = jQuery.grep(selectedIds, function (item) {
  48.             return jQuery.inArray(item, deselectedIds) < 0;
  49.         });
  50.         var gridID = ($(e.target.id).selector);
  51.         $('#' + gridID + ' :checkbox').each(function () {
  53.             $(this).attr('checked', jQuery.inArray($(this).val(), selectedIds) > -1);
  55.         });
  56.     }
  57. </script>
  58. @{ Html.Telerik().Grid<TelerikGridWithCheckboxes.Controllers.Order>()
  59.         .Name("Grid")
  60.         .Columns(columns =>
  61.         {
  62.             columns.Bound(o => o.OrderId)
  63.             .ClientTemplate("<input type='checkbox' id='OrderId' name='OrderId' value='<#= OrderId #>' <#= IsChecked ? checked='checked' : '' #>/>")
  64.                    .Title("")
  65.                    .Width(36)
  66.                    .HtmlAttributes(new { style = "text-align:center" });
  68.             columns.Bound(o => o.OrderId).Width(100);
  69.             columns.Bound(o => o.OrderName).Width(200);
  70.         })
  71.         .DataBinding(dataBinding => dataBinding.Ajax()
  72.                 .Select("_CheckBoxesAjax", "Home"))
  73.                 .ClientEvents(c => c.OnDataBound("OnCheckBoxGridDataBound"))
  74.         .Scrollable()
  75.         .Pageable()
  76.         .Render();
  77. }



Ganesh D

WCF # 22 Error Handling , Error Logging , ErrorHandlerAttribute using WCF Extensions

March 26, 2013 3 comments


In this article , we will see how to write the generic error handler in the WCF which is used for custom error logging and in returning the appropriate fault message to the user if any error comes while processing the user request.

IErrorHandler interface is used for error handling and logging in the WCF.

  1. public interface IErrorHandler
  2. {
  3.     bool HandleError(Exception error);
  4.     void ProvideFault(Exception error, MessageVersion version, ref Message fault);
  5. }

HandleError method logs an error.
It returns true if the error is considered as already handled other wise false will be returned and error will be handled as usual.

ProvideFault method can only be used in DUPLEX communication.
This method allows to create the custom FaultException
This method accepts the parameter error which is of type Exception , this exception is the exception occurs during the execution of a service method.


Following is the code for IErrorHandler interface Implementation.                                         

IErrorHandler Implementation
  1. [AttributeUsage(AttributeTargets.Class)]
  2. public class ErrorHandlerBehaviorAttribute : Attribute, IErrorHandler, IServiceBehavior
  3. {
  4.     //IErrorHandler Implementation
  6.     bool IErrorHandler.HandleError(Exception error)
  7.     {
  8.         try
  9.         {
  10.             //Write your code here for Logging the errors
  11.         }
  12.         catch { }
  13.         return false;
  14.     }
  16.     void IErrorHandler.ProvideFault(Exception error, MessageVersion version, ref Message fault)
  17.     {
  18.         if (OperationContext.Current != null && OperationContext.Current.IncomingMessageHeaders != null)
  19.         {
  20.             //Write code here for modifying the Fault Messages to be returned to the USER
  21.         }
  23.     }
  25.     //IServiceBehavior implementation"
  27.     void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase host)
  28.     {
  29.         //attach the object implementing the IErrorHandler interface(this class itself) to each ChannelDisp
  31.         foreach (ChannelDispatcher dispatcher in host.ChannelDispatchers)
  32.         {
  33.             dispatcher.ErrorHandlers.Add(this);
  34.         }
  35.     }
  37.     void IServiceBehavior.Validate(ServiceDescription description, ServiceHostBase host)
  38.     {
  39.         //implementation not required at present. Can be added later if required.
  40.     }
  41.     void IServiceBehavior.AddBindingParameters(ServiceDescription description, ServiceHostBase host,
  42.         Collection<ServiceEndpoint> endpoints, BindingParameterCollection parameters)
  43.     {
  44.         //implementation not required at present. Can be added later if required.
  45.     }
  48. }


Brief Summary for the code above

1) It has been derived from the Attribute class so that it can be used as an attribute over the service class directly.

2)It has been also derived from IServiceBehaviour interface which is used to apply this ErrorHandler behavior to the channel dispatcher in the Service

void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase host)


    //attach the object implementing the IErrorHandler interface(this class itself) to each ChannelDispatcher

    foreach (ChannelDispatcher dispatcher in host.ChannelDispatchers)






Now our ErrorHandlerBehavior attribute is ready to use on any WCF service.The benefit of creating the atttribute for this behavior is we can directly use this in the c# code on the service class as below

Add behavior to service
  1. [ErrorHandlerBehavior()]
  2.     public class Service : IService
  3.     {
  4.      //Implement your IService methods here
  5.     }



Ganesh D

LINQ # 10 – Join with multiple columns of the same table using Linq


While using LINQ as Linq to Sql queries , We often come across a scenario where we have to join the same table for multiple columns in it.

Following example illustrates how we can achieve it in Linq :

We have two tables Table1 and Table2 with columns column1 and column2 and we  have to join the Table1 with Table2 for both the columns.

We can achieve it using AnonymousType introduced by Microsoft.

Following is the code used for it


Join with multiple columns
  1. var lstDetails=(from tbl1 in Table1
  2.                 join tbl2 in  Table2
  3.                 on new {tbl1.column1,tbl1.column2}
  4.                 equals new {tbl2.column1,tbl2.column2}
  5.                 select tbl1 );

Thanks,                                                                                                                                          Ganesh

ASP.NET – Call Synchronous Method Asynchronously using C# ,.net (Fire and forget pattern)


Hi Friends,

Many times we come across a situation when we need to call a method asynchronously and don’t want to wait till it completes its execution.


Call Method Asynchronously
  1. class Program
  2.     {
  3.         public delegate void AsyncMethodCaller(int Application_Type_Id);
  5.         public static void AsynchronousMethod(int Application_Type_Id)
  6.         {
  7.             Console.WriteLine("My Application_Id is {0}",Application_Type_Id);
  9.         }
  10.         static void Main()
  11.         {        
  12.            AsyncMethodCaller caller = new AsyncMethodCaller(AsynchronousMethod);
  13.            IAsyncResult result = caller.BeginInvoke(1, null, null);
  14.            Console.Read();
  16.         }
  18.     }


For Example In the above code, if I want to call AsynchronousMethod() and not wait for it to finish executing? In fact, to make things interesting, what if I didn’t care when it is finished?

Let’s say, I just wanted to call AsynchronousMethod() without waiting for any of the function calls to complete. Basically, doing something called Fire and Forget. You call the function, you don’t wait for it, and you just forget about it.

Note :

* BeginInvoke() is the line of code that executes the AsynchronousMethod() function. However, the control is returned to the caller right away, without waiting for AsynchronousMethod() to complete.

* The code above does not know when a call to AsynchronousMethod() completes.

* BeginInvoke() is used instead of Invoke(). For now, don’t worry about the parameters this function takes; I will cover that in more detail later.


How .NET works in background to make this Possible?

Once you ask the framework to call something asynchronously, it needs a thread to do the work. It can not be the current thread, because that would make the invocation synchronous (blocking). Instead, the runtime queues a request to execute the function on a thread from the .NET Thread Pool. You don’t really need to code anything for it, all of it happens in the background. But, just because it is all transparent doesn’t mean you should care about it. There are a few things to remember:

* AsynchronousMethod() is executed on a separate thread, a thread that belongs to the .NET Thread Pool.

* A .NET Thread Pool contains threads in it , and each time AsynchronousMethod() is called, it is going to be executed on one of these threads. You can’t control which one.

* The Thread Pool has its limits! Once all the threads are used, an async method invocation is queued until one of the threads from the pool is freed. This is called Thread Pool Starvation, and normally when it comes to that, performance is compromised.



Hope this Helps!!!!!!Smile

Categories: ASP.NET

ASP.NET–Asynchronous HTTP Module

January 27, 2012 2 comments

Hi Friends,

An HTTP module is an object that sits in the ASP.NET pipeline, where it can see-and even modify-incoming requests and outgoing responses.

Today while working with website containing multiple applications , I faced a scenario where i need to  log incoming requests in database . By collecting the login name, a date and time, and the application that the user accessed during the login session.

By thinking on above scenario one would say what’s a big deal in this!! we can make entry every time the user clicks on the application .but problem with this solution is it would give call to the database every time user clicks on any application. First, it performs database insert. Second, it uses a request-processing thread to perform the I/O-a thread that could otherwise be used to service additional incoming requests, which imposes a penalty on throughput.

So for this we decided to write a http module which made it possible for us, but Question is How httpModule improve our performance / throughput the answer is ASYNCHRONOUS HttpModule.

Asynchronous Http Module
  1. public class AsyncModule : IHttpModule
  2.     {
  3.         /// <summary>
  4.         /// You will need to configure this module in the web.config file of your
  5.         /// web and register it with IIS before being able to use it. For more information
  6.         /// see the following link: http://go.microsoft.com/?linkid=8101007
  7.         /// </summary>
  8.         #region IHttpModule Members
  10.         string conString = "Data Source=localhost;initial catalog=OpenLDAP;integrated security=true;Asynchronous Processing=true";
  11.         SqlConnection con;
  12.         SqlCommand cmd;
  15.         public void Dispose()
  16.         {
  17.             if (con != null)
  18.                 con.Close();
  19.         }
  21.         public void Init(HttpApplication context)
  22.         {
  23.             context.AddOnPreRequestHandlerExecuteAsync(new BeginEventHandler(OnBeginAsync), new EndEventHandler(OnEndAsync));
  24.         }
  26.         #endregion
  28.         public void OnLogRequest(Object source, EventArgs e)
  29.         {
  30.             //custom logging logic can go here
  31.         }
  32.         IAsyncResult OnBeginAsync(Object source, EventArgs e, AsyncCallback cb, Object state)
  33.         {
  35.             //Write your logic here to track the Request//
  36.             con = new SqlConnection(conString);
  37.             con.Open();
  38.             cmd = new SqlCommand();
  39.             cmd.Connection = con;
  40.             cmd.CommandText = "Insert into documents values('abstract3','title',null)";
  41.             return cmd.BeginExecuteNonQuery(cb, state);
  43.         }
  44.         public void OnEndAsync(IAsyncResult result)
  45.         {
  46.             cmd.EndExecuteNonQuery(result);
  48.         }
  50.     }

How above module works asynchronous???

Its Init method calls HttpApplication.AddOnPreRequestHandlerExecuteAsync in order to register begin and end methods for PreRequestHandlerExecute events.

The HttpApplication class features other AddOn methods for other per-request events. For example, an HTTP module can call AddOnBeginRequestAsync to register async handlers for BeginRequest events.

AsyncRequestLogModule’s OnBeginAsync method uses the framework’s BeginExecuteNonQuery method to begin an asynchronous insert. The moment OnBeginAsync returns, the thread goes back into the thread pool.

Thank You,

Hope this helps Smile

Categories: Uncategorized