Microsoft ASP.NET Programming


This page discusses how to program in ASP.NET by using C# from the beginning.
  1. Check the Microsoft ASP.NET Help Pages.

  2. Download and Install Visual Studio Community.
  3. Visual Studio is a full-featured integrated development environment (IDE) for Android, iOS, Windows, web, and cloud. It has three editions:


    Visual Studio Community, a revamped edition of Visual Studio Professional, is free for individual. VS Community is not a trial version, nor an Express-style narrowly limited product. It is the same as Visual Studio Professional, except that it does not include the CodeLens feature, and it is activated through a Microsoft account instead of a product key.

  1. Start the Visual Studio Community 2019.
  2. Select the following Windows options:
       Start ⇒ All Programs
             ⇒ Visual Studio 2019
    If you want to open an existing project, pick the project with the .sln (solution) file extension as follows. Otherwise, go to the next step.


  3. Create a New Web Application.
  4. Follow the next steps:

    1. Pick the option “Create a new project:”


    2. Select the template “ASP.NET Web Application (.NET Framework):”


    3. Configure the application by entering the following information:

      • Project name such as “WebApplication1,”
      • Location such as “C:\ASP.NET-workspace\,” and
      • Checking “Place solution and project in the same directory.” A solution is a container for projects. A single solution may contain zero or more projects. Loading the solution file will load all the associated projects. Unchecking this option puts the projects under the solution and may generate a path like “C:\ASP.NET-workspace\WebApplication1\WebApplication1\WebForm1.aspx
      • instead of “C:\ASP.NET-workspace\WebApplication1\WebForm1.aspx”.


    4. Create a new ASP.NET web application by selecting the template “Empty” or “Web Forms:”


    5. Visual Studio IDE (integrated development environment) will be displayed as follows:

  1. Create a Web Page.
  2. This web application is to display the user name entered from the previous page. Take the following steps to create the first page:
    1. Select the options:
         Project ⇒ Add New Item...
    2. Pick the template: “Web Form” and “Visual C#” and
    3. Give a name, such as “C:\ASP.NET-workspace\WebApplication1\WebForm1.aspx”.



  1. Create the User Interface of the Web Form WebForm1.aspx.
  2. Visual Studio Community 2019 includes a WYSIWYG, drag-and-drop user interface. Build the interface as follows:


    which includes the followings tools:


    The source code of WebForm1.aspx is partially, automatically generated as follows:

    C:\ASP.NET-workspace\WebApplication1\WebForm1.aspx
     <%@ Page Language="C#" AutoEventWireup="true"
       CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
    
     <!DOCTYPE html>
     <html xmlns="http://www.w3.org/1999/xhtml">
      <body>
       <form id="form1" runat="server">
        <div>
         <asp:Label ID="Label1" runat="server" Font-Bold="True"
           Font-Size="Large" Text="Welcome to ASP.NET!">
         </asp:Label>
         Name:
         <asp:TextBox ID="textBox1" runat="server" Width="142px">
         </asp:TextBox>
         <asp:Button ID="button1" runat="server" Text="Submit" />
        </div>
       </form>
      </body>
     </html>
  1. Implement the Web Page WebForm1.aspx.
  2. For how to program in ASP.NET, check the ASP.NET Tutorial. Double click the button “Submit” in the design of WebForm1.aspx. The tab WebForm1.aspx.cs of a CS template will be generated. Complete the C# function button1_Click as follows:


    C:\ASP.NET-workspace\WebApplication1\WebForm1.aspx.cs
     using System;
    
     namespace WebApplication1 {
       public partial class WebForm1 : System.Web.UI.Page {
    
         protected void button1_Click( object sender, EventArgs e ) {
           Response.Redirect( "WebForm2.aspx?name=" + textBox1.Text );
         }
    
         protected void button2_Click( object sender, EventArgs e ) {
           Response.Close( );
         }
       }
     }

  3. Create the Web Form WebForm2.aspx.
  4. Build the interface as follows:


    which includes the following tools:

  1. Implement the Web Page WebForm2.aspx.cs.
  2. Double click the button “Home” in the design of WebForm2.aspx. The tab WebForm2.aspx.cs of a C# template will be generated. Complete the C# functions Page_Load and button1_Click as follows:


    C:\ASP.NET-workspace\WebApplication1\WebForm2.aspx.cs
     using System;
    
     namespace WebApplication1 {
       public partial class WebForm2 : System.Web.UI.Page {
         
         protected void Page_Load( object sender, EventArgs e ) {
           label1.Text = Request.QueryString["name"];
         }
    
         protected void button1_Click( object sender, EventArgs e ) {
           Response.Redirect( "WebForm1.aspx" );
        }
       }
     }

  3. Build and Debug the Web Application.
  4. Build the web application by selecting the following options:
       Build ⇒ Build Solution
    If the build is successful, debug the web application by selecting the options:
       Debug ⇒ Start Without Debugging
    One example of execution results is shown as follows:

    Submit ⇒

    ⇐ Home

    Start testing your web site. Unless there are a web server and an IP address on your machine, the web pages can only be accessed by a browser on the local machine. You can see this by noticing the URL is, for example,
       http://localhost:44308/WebForm1.aspx
    For demostration, you may save the web site in a flash drive or in the cloud.