My "Hello World" in ASP

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

Post Reply
user_797
New Member
Posts: 1
Joined: Mon 17 Dec, 2007 12:00 pm

My "Hello World" in ASP

Post by user_797 »

I have written my first "Hello World" program in ASP. I thought I would post here how it is done and ask if anyone can suggest how to incorporate C#.

The first step was to download the free "Microsoft Visual Web Developer 2005 Express Edition" from microsoft.com

The next step was to install and run this program. Then create a new web page by clicking on File -> New Web Page. This will bring up this windowL

[img]i67.photobucket.com/albums/h292/Athono/aspnet05.png[/img]
From this window, pick "ASP.Net Web Site" and click the OK button.

Then I edited the Default.aspx file so it reads like this:

Code: Select all

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%
    HelloWorldLabel.Text = "Hello, world!"
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Label runat="server" id="HelloWorldLabel"></asp:Label>

    </div>
    </form>
</body>
</html>
And this works.

So the next step is to incorporate C# into this "Hello World" program. Can anyone make a suggestion?
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

Would changing VB to C# and the VB to C# code work?

I have no idea whether it actually works, but you could try

Code: Select all

<%@ Page Language="C#" AutoEventWireup="false" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%
    HelloWorldLabel.Text = "Hello, world!";
%> 
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

Visual Studio 2008 Express has been released, and gives you access to C#3/VB9 and a host of new features. (You can still target .NET 2.0 runtimes if you need to, though). Websites tend to be data driven, and LINQ is therefore quite appealing. :) On the web development front, you'll also get access to Silverlight.

As for a C# website... I just fired up VWD and picked "Visual C#" from the "Language" dropdown. :)

Generally, you should try and separate the logic from the interface. If you expand the Default.aspx file you should see a code file, Default.aspx.cs (or .vb in your case). You can put the code in there, like this:

Code: Select all

using System;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.HelloWorldLabel.Text = "Hello, World";
    }
}
Hm, I really should get around to learning ASP.NET properly, but my host only supports PHP4 and some clone of classic ASP (Chili!Soft ASP). Learning ASP.NET (and thus having a nice language and a nice framework) would just end up depressing me. :(
Post Reply