请问session问题 !!!

snowtscx 2010-01-05 11:47:37
我用下面的代码,想实现每次点击按钮时Session["c_num"]加1,可是实现起来变成每次点击按钮后,Page_Load的时候Session["c_num"]的值都是null,而不是上一次加1,请问应该如何修改,谢谢!

protected void Page_Load(object sender, EventArgs e)
{
if (Convert.ToInt32(Session["c_num"]) == 0)
{
Session["c_num"] = 1;
}
}

protected void ImageButton_add_Click(object sender, ImageClickEventArgs e)
{
Session["c_num"]=Convert.ToInt32(Session["c_num"])+1;
}
...全文
96 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
snowtscx 2010-01-05
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 asharpnet 的回复:]
C# codeif(!IsPostBack)
{if((Session["c_num"])==null)
{
Session["c_num"]=1;
}
}
[/Quote]

不行
asharpnet 2010-01-05
  • 打赏
  • 举报
回复

if(!IsPostBack)
{
if((Session["c_num"])==null)
{
Session["c_num"]=1;
}
}
snowtscx 2010-01-05
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 happyer_longlong 的回复:]
if ((Session["c_num"]) ==null)
        {
            Session["c_num"] = 1;
        }
试试  这个 ,  Session  默认是null 吧 ,你怎么能把他判断成 0 那
[/Quote]

一样,还是null
kushirong 2010-01-05
  • 打赏
  • 举报
回复
呵呵
happyer_longlong 2010-01-05
  • 打赏
  • 举报
回复
if ((Session["c_num"]) == null)
{
Session["c_num"] = 1;
}
试试 这个 , Session 默认是null 吧 ,你怎么能把他判断成 0 那
snowtscx 2010-01-05
  • 打赏
  • 举报
回复
不是第一次,而是无论点多少次,之前加过的都没有了,还是null.
honkerhero 2010-01-05
  • 打赏
  • 举报
回复
第一次启动时,肯定是NULL,按钮事件是在PAGE——LOAD之后运行的

110,571

社区成员

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

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

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