Create a new Web site, including two pages, with the following code:
1, index.aspx Code:
Copy Code code as follows:
<%@ Page language= "C #" autoeventwireup= "true" codefile= "Index.aspx.cs" inherits= "Index"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> Untitled Page </title>
<body>
<form id= "Form1" runat= "Server" >
<div>
<table style= "width:300px; height:100px ">
<tr>
<TD style= "width:100px" >
User name:</td>
<TD style= "width:246px" >
<asp:textbox id= "TextBox1" runat= "Server" ></asp:TextBox></td>
</tr>
<tr>
<TD style= "width:100px" >
Password:</td>
<TD style= "width:246px" >
<asp:textbox id= "TextBox2" runat= "Server" textmode= "Password" ></asp:TextBox></td>
</tr>
<tr>
<TD style= "Text-align:center" colspan= "2" >
<asp:button id= "Button1" runat= "server" text= "login" onclick= "Button1_Click"/></td>
</tr>
</table>
</div>
</form>
</body>
Index.aspx.cs Code:
Copy Code code as follows:
Using System;
Using System.Data;
Using System.Configuration;
Using System.Collections;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
public partial class Index:System.Web.UI.Page
{
String Strinfo;
protected void Page_Load (object sender, EventArgs e)
{
}
protected void Button1_Click (object sender, EventArgs e)
{
application["Info"] = TextBox1.Text;
Strinfo = application["Info"]. ToString ();
if (TextBox1.Text = "admin" && TextBox2.Text = = "Admin")
{
session["name"] = TextBox1.Text;
Response.Redirect ("default.aspx?") Info= "+ Strinfo +" ");//The value of the address bar
}
}
}
2, Default.aspx code:
<%@ Page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> Untitled Page </title>
<body>
<form id= "Form1" runat= "Server" >
<div>
<table style= "width:500px; Height:323px ">
<tr>
<TD colspan= "2" >
<asp:textbox id= "TextBox2" runat= "Server" height= "314px" width= "497px" textmode= "MultiLine" ></asp:textbox ></td>
</tr>
<tr>
<td>
<asp:label id= "Label1" runat= "Server" text= "Label" ></asp:Label>
<asp:textbox id= "TextBox1" runat= "Server" width= "390px" ></asp:TextBox></td>
<td>
<asp:button id= "Button2" runat= "Server" text= "send" onclick= "button2_click"/></td>
</tr>
</table>
</div>
</form>
</body>
Default.aspx.cs Code:
Using System;
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
public partial class _default:system.web.ui.page
{
protected void Page_Load (object sender, EventArgs e)
{
Label1.Text = session["Name". ToString ();
/* Increase of objects
Application.add ("App1", "Value1");
Application.add ("App2", "Value2");
Application.add ("App3", "Value3");
Response.Write ("Use of application Objects");
Response.Write ("<br>");
for (int i = 0; i < Application.count; i++)
{
Response.Write ("Variable name:" + application.getkey (i));
Response.Write (", Value:" + application[i] + "<p>");
Response.Write ("<br>");
}*/
}
protected void button2_click (object sender, EventArgs e)
{
application["content"] = TextBox1.Text;
TextBox2.Text = TextBox2.Text + "\ n" + Label1.Text + "said:" + application["content"]. ToString ();
}
}