Start ⇒ All Programs ⇒ Visual Studio 2019If you want to open an existing project, pick the project with the
.sln
(solution) file extension as follows.
Otherwise, go to the next step.
WebApplication1
,”C:\ASP.NET-workspace\
,” andC:\ASP.NET-workspace\WebApplication1\WebApplication1\WebForm1.aspx
”C:\ASP.NET-workspace\WebApplication1\WebForm1.aspx
”.Project ⇒ Add New Item...
C:\ASP.NET-workspace\WebApplication1\WebForm1.aspx
”.
WebForm1.aspx
.Label
, whose value of the property Text
is “Welcome to ASP.NET!”,
TextBox
, whose value of the property ID
is textBox1
, and
Button
s, whose values of the property ID
are button1
and button2
, and values of the property Text
are Submit
and Exit
, respectively.
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> |
WebForm1.aspx
.WebForm1.aspx
.
The tab WebForm1.aspx.cs
of a CS template will be generated.
Complete the C# function button1_Click
as follows:
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( ); } } }
WebForm2.aspx
.Label
, whose value of the property Name
is label1
, and
Button
, whose values of the property Name
and Text
are button1
and Home
, respectively.
WebForm2.aspx.cs
.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:
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" ); } } }
Build ⇒ Build SolutionIf the build is successful, debug the web application by selecting the options:
Debug ⇒ Start Without DebuggingOne example of execution results is shown as follows:
Submit ⇒ ⇐ Home |
http://localhost:44308/WebForm1.aspxFor demostration, you may save the web site in a flash drive or in the cloud.