test6-3
webform1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="test6_3.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td><strong>友情链接:<br /></strong></td>
</tr>
<tr>
<td>
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">百度</asp:LinkButton>
</td>
</tr>
<tr>
<td>
<asp:LinkButton ID="LinkButton2" runat="server" OnClick="LinkButton2_Click">网易</asp:LinkButton>
</td>
</tr>
<tr>
<td>
<asp:LinkButton ID="LinkButton3" runat="server" OnClick="LinkButton3_Click">腾讯</asp:LinkButton>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
webform1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace test6_3
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("http://www.baidu.com");
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
Response.Redirect("http://www.163.com");
}
protected void LinkButton3_Click(object sender, EventArgs e)
{
Response.Redirect("http://www.qq.com");
}
}
}
test6-4
webform1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="test6_4.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
用户名:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
密 码:<asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="登录" OnClick="Button1_Click" />
</div>
</form>
</body>
</html>
webform1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace test6_4
{
public partial class WebForm1 : System.Web.UI.Page
{
private static readonly string[] users = new string[] {"admin","user"};
private int userType(string userid)
{
if (userid == users[0])
{
return 1;
}
if (userid == users[1])
{
return 2;
}
return 0;
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string userid = TextBox1.Text.ToString();
string pwd = TextBox2.Text.ToString();
ViewState["UserType"] = userType(userid);
switch(ViewState["UserType"].ToString())
{
case "1":
Response.Redirect("Admin.aspx?userid=" + userid);
break;
case "2":
Response.Redirect("User.aspx?userid=" + userid);
break;
default:
Response.Write("<script>alert('不是合法用户');</script>");
break;
}
}
}
}
User.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace test6_4
{
public partial class User : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string user = Request.QueryString["userid"].ToString();
Response.Write( user +",登录成功");
}
}
}
Admin.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace test6_4
{
public partial class Admin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string admin = Request.QueryString["userid"].ToString();
Response.Write(admin + ",进入成功");
}
}
}
test6-5
webform1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="test6_5.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
webform1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace test6_5
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
System.IO.StreamReader reader = new System.IO.StreamReader(System.IO.File.Open(Server.MapPath("WebForm1.aspx"),System.IO.FileMode.Open));
string tmp;
while((tmp = reader.ReadLine()) != null)
{
Response.Write(Server.HtmlEncode(tmp) + "<br>");
}
reader.Close();
}
}
}
test6-6
webform1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="test6_6.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
用户名:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CheckBox ID="CheckBox1" runat="server" Text="记住我" /><br />
密码:<asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="登录" OnClick="Button1_Click"/>
</div>
</form>
</body>
</html>
webform1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace test6_6
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["ID"] != null && Request.Cookies["PWD"] != null)
{
string id = Request.Cookies["ID"].Value.ToString();
string pwd = Request.Cookies["PWD"].Value.ToString();
Response.Redirect("New.aspx?id=" + id + "&PWD=" + pwd);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (CheckBox1.Checked)
{
Response.Cookies["ID"].Expires = DateTime.Now;
Response.Cookies["PWD"].Expires = DateTime.Now;
Response.Cookies["ID"].Value = TextBox1.Text;
Response.Cookies["PWD"].Value = TextBox2.Text;
}
Response.Redirect("New.aspx?id=" + TextBox1.Text + "&PWD=" + TextBox2.Text);
}
}
}
News.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace test6_6
{
public partial class New : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["ID"] != null && Request.QueryString["PWD"] != null)
{
Response.Write("" + Request.QueryString["ID"] + "欢迎登录");
}
}
}
}
test6-7
webform1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="test6_7.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="清空购物车" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="添加" OnClick="Button2_Click" /><br />
<asp:Label ID="Label1" runat="server" Text="" ForeColor="Blue"></asp:Label>
</div>
</form>
</body>
</html>
webform1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace test6_7
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "商品数量:0";
}
protected void Button1_Click(object sender, EventArgs e)
{
Session["ItemCount"] = 0;
Label1.Text = "商品数量:" + Session["ItemCount"];
}
protected void Button2_Click(object sender, EventArgs e)
{
if (Session["ItemCount"] != null)
{
int i = int.Parse(Session["ItemCount"].ToString());
i++;
Session["ItemCount"] = i;
}
else
{
Session["ItemCount"] = 1;
}
Label1.Text = "商品数量:" + Session["ItemCount"];
}
}
}
test6-8
webform1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="test6_8.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
你是本站的第
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
位访客,欢迎你!
</div>
</form>
</body>
</html>
webform1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace test6_8
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int count = Convert.ToInt32(Application["Visitors"]);
Label1.Text = count.ToString();
}
}
}