62,041
社区成员
发帖
与我相关
我的任务
分享
<%@ 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">
<script language="c#" runat="server">
void Page_Load(Object src, EventArgs e)
{
Application.Add("counter", 0);
if (!Page.IsPostBack)//如果用户单击刷新按钮,计数器不加1
{
int num;
Application.Lock;
Application["counter"] = (int)Application["counter"] + 1;
num = (int)Application["counter"];
Application.UnLock;
label1.Text = Convert.ToString(num);
}
}
</script>
<body>
<form id="Form1" runat="server">
<asp:Label id="label1" Text="" runat="server"></asp:Label>
<asp:HyperLink id="hLink1" NavigateUrl = "other.aspx" Target="_blank" runat="server">
单击此处转到e1.aspx,计数器不加1。
</asp:HyperLink >
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Application.Lock();
Application["PageClick"] = (int)Application["PageClick"] + 1;
Application.UnLock();
Response.Write(string.Format("页面单击数:{0}<br/>", Application["PageClick"]));
Response.Write(string.Format("用户访问数:{0}<br/>", Application["UserVisit"]));
}
}
<%@ Page %>
<!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>
<script language="c#" runat="server">
private static int counter;
void Page_Load(Object src, EventArgs e)
{
int num;
lock (this.GetType())
{
counter++;
num = counter;
}
label1.Text = Convert.ToString(num);
}
</script>
</head>
<body>
<form id="Form1" runat="server">
<asp:Label ID="label1" Text="" runat="server"></asp:Label>
<asp:HyperLink ID="hLink1" NavigateUrl="other.aspx" Target="_blank" runat="server">
单击此处转到e1.aspx,计数器不加1。
</asp:HyperLink>
</form>
</body>
</html>