Article
Getting Started with ASP.NET
The VB.NET version
As I said earlier, ASP.NET lets you use your choice of a number of programming languages to write the script blocks in your pages. For the sake of comparison, here's the example we just looked at converted to VB.NET:
<%@ Page Language="VB" %>
<html>
<head>
<title>My First ASP.NET Page</title>
<script runat="server">
Sub Page_Load(Source As Object, E As EventArgs)
TimeLabel.Text = DateTime.Now.ToString()
End Sub
</script>
</head>
<body>
<p>Hello there!</p>
<p>The time is now: <asp:label runat="server" id="TimeLabel" /></p>
</body>
</html>
As you can see, the only parts of the page that have changed are the page directive, which now specifies VB as the language in use on the page, and the code block.
I won't waste your time describing the three lines of VB.NET code in the script block; if you look at it closely, you'll see that it is essentially identical to the C# code from our original example. All that's changed is the language syntax.
To prove to yourself that the two examples are equivalent, type the above code into you text editor and save it as hellothere-vb.aspx. If you view it in your browser, you'll see that it's identical to the C# example, right down to the HTML code that it generates.
Note: the filename of an ASP.NET page doesn't have to contain -vb or -cs to identify the language in use; I simply did that for our own benefit, to keep our examples organized. All ASP.NET pages should end with .aspx, however.
Stay tuned...
In my next article, I'll show you how to use ASP.NET to create and process forms on the Web! Until then, I welcome your comments!