private void Page_Load(object sender, System.EventArgs e)
{
Response.Cookies["Count"].Value = "100";
for(int i=0;i<5;i++)
{
Response.Cookies["Count"].Value = Convert.ToString(Convert.ToInt32(Request.Cookies["Count"].Value)+1);
Response.Write(Request.Cookies["Count"].Value+"<br>");
}}
第一次访问页面结果如下:101
102
103
104
105然后在不停的刷新页面,却成了下面形式?为什么不是第一次的结果呢??105
105
105
105
105---------
106
106
106
106
106------------107
107
107
107
107
{
Response.Cookies["Count"].Value = "100";
for(int i=0;i<5;i++)
{
Response.Cookies["Count"].Value = Convert.ToString(Convert.ToInt32(Request.Cookies["Count"].Value)+1);
Response.Write(Request.Cookies["Count"].Value+"<br>");
}}
第一次访问页面结果如下:101
102
103
104
105然后在不停的刷新页面,却成了下面形式?为什么不是第一次的结果呢??105
105
105
105
105---------
106
106
106
106
106------------107
107
107
107
107
{
if(!IsPostBack){
Response.Cookies["Count"].Value = "100";
for(int i=0;i<5;i++)
{
Response.Cookies["Count"].Value = Convert.ToString(Convert.ToInt32(Request.Cookies["Count"].Value)+1);
Response.Write(Request.Cookies["Count"].Value+"<br>");
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
Response.Cookies["Count"].Value = "100";
for (int i = 0; i < 5; i++)
{
Response.Cookies["Count"].Value = Convert.ToString(Convert.ToInt32(Response.Cookies["Count"].Value) + 1);
Response.Write(Response.Cookies["Count"].Value + "<br>");
}
}