Getting Started with ASP.NET Web Forms: Your First “Hello, World!” App

Introduction

When diving into any new programming framework, it’s a tradition to start with a simple “Hello, World!” example. So, let’s honor that tradition and walk through how to display this classic message using ASP.NET Web Forms.

Step 1. Open Your Web Form

Begin by opening Default.aspx from your project. You’ll notice it already contains a mix of HTML and some unfamiliar ASP.NET-specific syntax—like the Page directive at the top and the runat="server" attribute on the <form> tag. Don’t worry if this looks confusing for now; we’ll focus on getting something up and running first.

Step 2. Add a Label Control

Inside the <form> tag, add the following ASP.NET Label control. This control is used to display text on the page:

<asp:Label runat="server" ID="HelloWorldLabel"></asp:Label>

Step 3. Write the Code to Display the Message

Now add a small block of inline server-side code near the top of the page, preferably right below the Page directive:

<%
    HelloWorldLabel.Text = "Hello, world!";
%>

This line sets the Text property of the Label control to display your message when the page loads.

Step 4. Run the Application

To see it in action, go to the Visual Studio menu and click Debug > Start Without Debugging or simply press Ctrl + F5. Visual Studio will build and launch your project in the default web browser. If everything went well, you’ll see the message “Hello, world!” displayed on the page.

Full Example Code

Here’s how your complete Default.aspx page should look:

<%
    HelloWorldLabel.Text = "Hello, world!";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>My First ASP.NET Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:Label runat="server" ID="HelloWorldLabel"></asp:Label>
        </div>
    </form>
</body>
</html>

Thanks for reading.