Create a website, including two webpages, Code As follows:
1. Index. aspx code:
Copy code The Code is 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">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Table Style = "width: 300px; Height: 100px">
<Tr>
<TD style = "width: 100px">
Username: </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 = "button#click"/> </TD>
</Tr>
</Table>
</Div>
</Form>
</Body>
</Html>
Index. aspx. CS code: Copy code The Code is 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 button#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 in 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">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
</Head>
<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>
</Html>
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 ();
/* Object addition
Application. Add ("app1", "value1 ");
Application. Add ("app2", "value2 ");
Application. Add ("app3", "value3 ");
Response. Write ("Application object usage ");
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 ();
}
}