碰到一个问题(我编写的是点击+1,出来的效果却是点击+2),疑惑,望指教

smalldeer 2003-08-20 03:22:02
private void Page_Load(object sender, System.EventArgs e)
{
Session["newsid"]=Request.QueryString.Get("newsid");
XX.XX.Service1 update_hits=new XX.XX.Service1();//调用服务程序中的webmethod
update_hits.Update_hits(Session["newsid"].ToString());//点击次数+1
}

窗体上还放置了一个button(text=关闭窗口)

private void Button1_Click(object sender, System.EventArgs e)
{
Response.Write("<script language=javascript>window.close();</script>");
}

测试的时候
如果我点击最上面的XX,点击+1
如果我点击button来关闭窗口,点击却是+2

疑惑,望指教

谢谢
...全文
21 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
smalldeer 2003-08-20
  • 打赏
  • 举报
回复
哈,就是这样if(!IsPostBack)没有+

现在可以了

谢谢

qimini 2003-08-20
  • 打赏
  • 举报
回复
Session["newsid"]=Request.QueryString.Get("newsid");
XX.XX.Service1 update_hits=new XX.XX.Service1();//调用服务程序中的webmethod
update_hits.Update_hits(Session["newsid"].ToString()<<<<
把这段改成
if(!IsPostBack)
{
Session["newsid"]=Request.QueryString.Get("newsid");
XX.XX.Service1 update_hits=new XX.XX.Service1();//调用服务程序中的webmethod
update_hits.Update_hits(Session["newsid"].ToString();
}
qimini 2003-08-20
  • 打赏
  • 举报
回复
Session["newsid"]=Request.QueryString.Get("newsid");
XX.XX.Service1 update_hits=new XX.XX.Service1();//调用服务程序中的webmethod
update_hits.Update_hits(Session["newsid"].ToString()<<<<
把这段改成
if(!IsPostBack)
{
Session["newsid"]=Request.QueryString.Get("newsid");
XX.XX.Service1 update_hits=new XX.XX.Service1();//调用服务程序中的webmethod
update_hits.Update_hits(Session["newsid"].ToString();
}
tibet 2003-08-20
  • 打赏
  • 举报
回复
因为web页面又刷新了一次呀,所以是+2呀

110,532

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧