Introduction to ASP.NET: Hello World

  1. Create new ASP.NET empty website called SimpleForm
  2. Add a new file and choose Web Form, ensuring the C# language is selected.
  3. On the design page type 'Welcome'. Press Enter and format 'Welcome' as Heading 1.
  4. Type the text 'What is your name? '.
  5. From the toolbox on the left hand side, drop a Textbox onto the end of the line.
  6. Drop a Button onto the next line and in its properties change the value of the 'text' property to 'Submit'.
  7. Drop a Literal onto the next line.
  8. You now have a web page containing various interactive elements. Their default names are TextBox1, Button1 and Literal1.
  9. Double click the Button.
  10. The design area should change to show some C# code with an empty function called Button1_Click, like this:
    protected void Button1_Click(object sender, EventArgs e)
    {
     
    }

    Note: this is an example of a default event handler. Clicking the button is an event. There are lots of events that can happen when the user is interacting with a webpage, however, for every element on a page there is a default event and Visual Studio will automatically create a function to handle it for you if you double click it in design view.

  11. In the blank line between the braces { } type your first piece of C# code as follows:
    protected void Button1_Click(object sender, EventArgs e)
    {
        Literal1.Text = "Hello " + TextBox1.Text;
    }

    The cursor moves down to match what you are typing and you can press enter to accept the current entry. This automatic predictive text feature is called 'intellisense'. You don't have to type along, as you can scroll down and select the option you want directly with either the mouse or the keyboard.

  12. Save your website and press the run button.
  13. When the page has compiled and is running you can type your name, press the Send button and the page will update with the message 'Hello <your name>' at the bottom.

This is a good start, but there are a number of ways we can improve the web application - try the Improved Hello World tutorial

This tutorial is a slightly modified version of one originally found at Scotty's Tutorials