Tutorials » AspNet tutorials »

Default programming language for ASP.NET

This article talks about the default programming language and other supported programming languages supported by ASP.NET

In the previous chapter, you learned how to display server time using ASP.NET. The code you wrote was,

Now the server time is :
Response.Write (DateTime.Now.ToString)

Now let us make some minor changes to the code so that we can explain some concepts better. Change the server side cide in your file Index.aspx under the folder C:\ShoppingCart as shown below:

Now the server time is :
dim currentTime as string = DateTime.Now.ToString
Response.Write ( currentTime )

We have declared a string variable and assigned the current time to it. Then we are doing a Response.Write ( currentTime ) so that the value is sent to the page output.

Let us view the new page now in browser. Type the URL http://localhost/ShoppingCart/index.aspx. You will see the same old result.

You may have noticed that we are using VB.NET syntax to write server side code.

In one of the previous chapters we mentioned that ASP.NET supports any programming language. Let us try it.

Change your server side code to C# syntax:

Now the server time is :
string currentTime = DateTime.Now.ToString();
Response.Write ( currentTime );

Try to view the page. You will get an error. What happens is, ASP.NET is trying to compile the server side code using vb compiler and it is giving an error (because it does not understand C# syntax).

How to use C# in ASP.NET ?

VB.NET is the default language for ASP.NET. This does not mean that VB.NET is a better choice than C#. Both VB.NET and C# are equally good for ASP.NET.

If you like to use a language other than the default VB.NET language, you must explicitely specify what language you are using so that ASP.NET can use appropriate compiler to compile your server side code.

Now we have changed our code to C# syntax. So, we must specify that we want to use C# compiler. What you need to do is, go to the top of the index.aspx page in notepad and type the following line:


The above line must be the first line in the aspx file. This statement tells the aspx page that it has to use C# compiler to compile the page.

We cannot mix more than one language in one page. If a page uses C# syntax, then you cannot use VB.NET syntax for some portion of the code in the same page.

You will learn about User Controls in one of the coming chapters. You can develop each User Control using a different language and place all those controls in one page.

Supported languages for ASP.NET

You can use any .NET programming language to write server side code in ASP.NET. The following are the .NET languages provided by Microsoft:

  • C#
  • VB.NET
  • C++
  • J#

Other companies are developing more .NET languages, which you will be able to use with ASP.NET. However, the widely used programming languages for ASP.NET are VB.NET and C#

Next Chapter: Difference between ASP and ASP.NET
Previous Chapter: Your first dynamic page
More Chapters: ASP.NET Tutorials
More Tutorials: Tutorial Index

Top Contributors
    Last 7 Daysmore...

    Awards & Gifts

    Online Members

    John Bhatt
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India