Section 1.2. Use Multiple Languages

1.2. Use Multiple Languages

Unlike ASP.NET 1.x, which requires that you use the same language throughout a web application, ASP.NET 2.0 lets you vary your languages from page to page within a project.

Note: You're no longer restricted to using a single language for your web applications.

Tip: While support for multiple languages is a useful feature, developers should use it in moderation (and only if necessary). Going with multiple languages in a single project is likely to increase the effort required in maintaining the project, particularly if the application ends up being maintained by someone who's not familiar with all the languages used.

Figure 1-7 shows a project with three pages, each of which is programmed with a different language: VB.NET (Default.aspx), C# (Default2.aspx), or VJ# (Default3.aspx).

Tip: VJ# does not support code-behind pages, so none appear for Page3.aspx in the Solution Explorer window.

Figure 1-7. A project with pages using different languages

1.2.1. How do I do that?

To verify that you can really mix languages in an ASP.NET 2.0 web application, in this lab you will create an application that uses two languages: VB.NET and C#.

  1. Using the project created in the last lab, add a new Web Form by right-clicking the project name in Solution Explorer and then selecting Add New Item.... Select Web Form from the list of installed templates.

  2. In the Add New Item dialog, you can choose the language you want to use, as shown in Figure 1-8. ASP.NET 2.0 supports three languages: VB2005, C#, and VJ#. Use the default name of Default2.aspx and choose the C# language. Click Add.

    Figure 1-8. Choosing the language to use

  3. In the Code View of Default.aspx, code the following:

    Protected Sub Page_Load(ByVal sender As Object, _                         ByVal e As System.EventArgs) _                         Handles Me.Load     Page.Title = "Page written in Visual Basic" End Sub

  4. In the Code View of Default2.aspx, code the following:

    void Page_Load(object sender, EventArgs e) {     Page.Title = "Page written in C#"; }

  5. To test the application, select Default.aspx in Solution Explorer and press F5. In IE, note the title of the window. Now, change the URL to load Default2.aspx. Figure 1-9 shows the effect of loading the two forms.

Figure 1-9. Loading two forms in an application written in two different languages

1.2.2. What about...

...using other .NET-supported languages such as C++, Python, or Perl?

Visual Studio 2005 will support only VB2005, C#, and VJ# for web development. The other languages are, however, available for other types of non-web projects.

1.2.3. Where can I learn more?

There is a good discussion on mixing languages in a .NET project at So before you go ahead and write your next ASP.NET web application using both VB.NET and C# (or J#), check out what other developers have to say.

ASP. NET 2.0(c) A Developer's Notebook 2005
ASP. NET 2.0(c) A Developer's Notebook 2005
Year: 2005
Pages: 104 © 2008-2017.
If you may any questions please contact us: