Sunday, 8 January 2012

Common Language Runtime(CLR)


What is CLR:
CLR stands for “Common Language Runtime”. CLR is the base for .NET Framework or we can say it is an “Application Virtual Machine” upon which the .NET Framework has been built. CLR manages code at runtime and the code managed by the CLR is called managed code.

CLR provides various services like exception handling, memory management, pre –emptive thread management, security and robustness for accessing code, cross-language integration, object lifetime management, resource management, type safety,  metadata services (type reflection) and profiling support to the applications.
Example: ASP.NET Framework, Internet Explorer (hosted by CLR)

CLR Features:
1.  CLR is an "execution engine” that manages the execution of programs.
 2. CLR provides execution environment for multiple languages. At that time there are more than
    15 that produce code that will execute in the CLR.
3. It is the implementation of CLI.
4. CLR provides secure file access operations, registry access operations
5. CLR provides a strict type and code verification infrastructure called Common Type System
   (CTS) that enforces code robustness
6.  CLR provides various properties like garbage clearance, object referencing, object handling. 
     These properties prevent memory leaks and invalid memory references.
7. Now programmers can select any language without worrying about the compatibility issues. 
    This increases the productivity of developers
6. CLR provides interoperability between managed and unmanaged code. 

How CLR works:
CLR works in the following way-

  • After compiling the .Net code, we found that the output of the compiler is not an executable file but a file that contains a special type of code called the Microsoft Intermediate Language (MSIL, now called CIL, Common Intermediate Language) .
  • So for changing MSIL into executable code the concept of CLR comes in to light.
  •   Now this MSIL is changed into executable code using a JIT (Just In Time) complier.It is the work of the CLR to activate the JIT complier. So we can say that JIT is responsible for converting MSIL into executable.




Thursday, 29 December 2011

How To Apply "ViewStateMode for individual control"


WHAT IS VIEWSTATE: 
View State property of ASP.NET provides the functionality of “automatically storing values between multiple requests” for the same page. It is a client side state management mechanism that can store the page value at the time of sending and receiving information from server.
Ex-Like EmailID, Username in various sites.

LIMITATION IN PREVIOUS VERSION:
In previous version of ASP.NET developer could not enable view state for individual controls. This functionality is available only at the page level.

Only the thing was available in previous version, developers could disable view state for individual controls in order to reduce page size, but had to do so explicitly for individual controls.

IMPROVEMENTS IN ASP.NET 4.0:                         
In ASP.NET 4.0, a ViewStateMode property is included that allows developer to disable viViewState at the page level and then enable it only for the controls that require it in the page. ViewStateMode has 3 values:
  • Enabled – enables the view state for this control and any child control.
  • Disabled – disable the view state.
  • Inherits – this specify the control uses the settings from its parent control.
 WHY MAKE CHANGES:
In earlier versions of ASP.NET by default this ViewState property is enabled at page level, so each control on the page potentially stores view state even if it is not required for the application. This increases the page size and the performance for our application is decreases.

To overcome this problem developer had to disable ViewState for individual control explicitly and it was very irritating for big applications.

HOW TO APPLY VIEW STATE MODE FOR INDIVIDUAL CONTROL:
For applying ViewState mode for individual control you have to follow these steps:
  • Disable ViewState at the page level in your application as shown in picture-
 


  •  Then write ViewStateMode=”Enabled” for the controls that require in the page as shown in the picture-

Now ViewState mode is enabled for the individual control that require in the page. This will reduce the page size aur now your application becomes more responsive.

BENEFITS:

•          This feature permits developer to enable viewstate for individual controls which are required in the page.
•          As  a result the size of the pages is reduced and your application becomes more responsive.
•          By applying this feature in your application, a significant performance improvement can be gained in response-time.
•          A good use for this feature is with ContentPlaceHolder controls in master pages, where ViewStateMode can be set to Disabled for the master page and then enable it individually for ContentPlaceHolder controls that in turn contain controls that require view state.