.Net Links

Thursday, February 10, 2011

How the Common Language Runtime Works

How the Common Language Runtime Works
The Common Language Runtime (CLR) manages the execution of .NET code. Here is how
it works. When you compile a C# program, the output of the compiler is not executable code.
Instead, it is a file that contains a special type of pseudocode called Microsoft Intermediate Language, or MSIL for short. MSIL defines a set of portable instructions that are independent of any specific CPU. In essence, MSIL defines a portable assembly language.

One other point:
Although MSIL is similar in concept to Java’s bytecode, the two are not the same.
It is the job of the CLR to translate the intermediate code into executable code when a program is run. Thus, any program compiled to MSIL can be run in any environment for which the CLR is implemented. This is part of how the .NET Framework achieves portability.
Microsoft Intermediate Language is turned into executable code using a JIT compiler. JIT stands for “just in time.” The process works like this: When a .NET program is executed, the CLR activates the JIT compiler. The JIT compiler converts MSIL into native code on a demand basis, as each part of your program is needed. Thus, your C# program actually executes as native code, even though it was initially compiled into MSIL. This means that your program runs nearly as fast as it would if it had been compiled to native code in the first place, but it gains the portability and security benefits of MSIL.

In addition to MSIL, one other thing is output when you compile a C# program: metadata.Metadata describes the data used by your program and enables your code to interact with other code. The metadata is contained in the same file as the MSIL.

Labels: , ,

Thursday, February 3, 2011

Execute JavaScript function from ASP.NET codebehind


Simple example of Calling a JavaScript function from codebehind is given below.



In order to call it from code behind, use the following code in your Page_Load

C#

protected void Page_Load(object sender, EventArgs e)
{
if (!ClientScript.IsStartupScriptRegistered("alert"))
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "alertMe", "javascript:alertMe(This is Sample JS Testing); ", true);
}
}

Labels: