What's new
HTML Forums | An HTML and CSS Coding Community

Welcome to HTMLForums; home of web development discussion! Please sign in or register your free account to get involved. Once registered you will be able to connect with other members, send and receive private messages, reply to topics and create your very own. Our registration process is hassle-free and takes no time at all!

ASP.NET First Program Example: Hello World

Sophia

New member
Let’s look at an example of how we can implement a simple “hello world” application. For this, we would need to implement the below-mentioned steps.

Step 1) The first step involves the creation of a new project in Visual Studio. After launching Visual Studio, you need to choose the menu option New->Project.

ASP.Net - Intro, Life Cycle & Hello World Program


Step 2) The next step is to choose the project type as an ASP.Net Web application. Here we also need to mention the name and location of our project.

  1. In the project dialog box, you can see various options for creating different types of projects. Click the Web option on the left-hand side.
  2. When we click the Web option in the previous step, we will be able to see an option for ASP.Net Web Application. Click this option.
  3. We then give a name for the application, which in our case is DemoApplication. We also need to provide a location to store our application.
  4. Finally, we click the ‘OK’ button to let Visual Studio to create our project.
ASP.Net - Intro, Life Cycle & Hello World Program


Step 3) In the next screen, you have to choose the type of ASP.net web application that needs to be created. In our case, we are going to create a simple Web Form application.

  1. First, choose the project type as ‘Empty’. This will ensure that we start with a basic application which is simple to understand.
  2. We choose the option “web Forms”. This adds the basic folders. These are required for a basic Web Forms Application.
  3. Finally, we click the ‘OK’ button to allow Visual Studio to create our application.
ASP.Net - Intro, Life Cycle & Hello World Program



If the above steps are followed, you will get the below output in Visual Studio.

Output:-

ASP.Net - Intro, Life Cycle & Hello World Program


In the Solution Explorer, you will be able to see the DemoApplication Solution. This solution will contain 2 project files as shown above. At the moment, one of the key files in the project is the ‘Global.asax.cs’. This file contains application specific information. In this file, you would initialize all application specific variables to their default values.

Step 4) Now, it’s time to add a Web Form file to the project. This is the file which will contain all the web-specific code for our project.

  • Right-click on the DemoApplication project and
  • Choose Add->Web Form from the context menu.
ASP.Net - Intro, Life Cycle & Hello World Program


Step 5) In the next screen we are going to be prompted to provide a name for the web form.

  1. Give a name for the Web Form. In our case, we are giving it a name of Demo.
  2. Click the Ok button.
ASP.Net - Intro, Life Cycle & Hello World Program


Automatically Visual Studio will create the Demo Web Form and will open it in Visual Studio.

Step 6) The next step is to add the code, which will do the work of displaying “Hello World.” This can be done by just adding one line of code to the Demo.aspx file.

ASP.Net - Intro, Life Cycle & Hello World Program


<html xmlns="www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<%Response. Write( "HeIIo World"); %>

</div>
</form>
</body>
</html>

Code Explanation:-

  • The Response object in ASP.Net is used to send information back to the user. So in our case, we are using the method “Write” of the Response object to write the text “Hello World.” The <% and %> markers are used to add ASP.net specific code.
If you follow all of the above steps and run your program in Visual Studio, you will get the following output.

Output:-

ASP.Net - Intro, Life Cycle & Hello World Program


From the output, you can clearly see that ‘Hello World’ was displayed in the browser.
 
Can you give a time frame when did this program ASP.net take place? I started computers in 1986. I'm learning computers using Java programming and learning it from on Top of C#. Windows. Java has import java.lang.Object packages in the software. So it comes out the same way. JFrame. Plus it's a network programming language, so I'm learning that. I'm taking this back only to 1995 when Java came on the scene and on the internet.

I started off with my very first program in Windows. Intel 8086 CPU Microsoft basic programming language. Hard drive and a floppy drive. C:\ was the dos prompt I started on. The applications then were new to me. Word or excel. I learned that quickly. Where does ASP.net fit in all of this. Website design. What are the application program name? Plus I'm just starting on Python programming. Website design. This works well also with HTML and BB codes.

I haven't touch all of the details of HTML markup language yet. So this will be good for me learning new tricks of the computer.
 
Last edited:
Back
Top