Asp. NET built-in object Application Object _ Practical Tips

Source: Internet
Author: User
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>
&LT;TD style= "width:100px" >
User name:</td>
&LT;TD style= "width:246px" >
<asp:textbox id= "TextBox1" runat= "Server" ></asp:TextBox></td>
</tr>
<tr>
&LT;TD style= "width:100px" >
Password:</td>
&LT;TD style= "width:246px" >
<asp:textbox id= "TextBox2" runat= "Server" textmode= "Password" ></asp:TextBox></td>
</tr>
<tr>
&LT;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>
&LT;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 ();
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.