页面加载时如何仅一次初始化会话值 [英] how to intialize session value only one time when page get load

查看:65
本文介绍了页面加载时如何仅一次初始化会话值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从事在线测验程序,根据我的计算来设置计时器值:
受保护的void UpdateTimer_Tick(对象发送者,EventArgs e)
{
TimeSpan time1 = new TimeSpan();
time1 =(DateTime)Session ["time"]-DateTime.Now;
如果(time1.Minutes< = 0)
{
如果(time1.Seconds< = 0)
{
//string strc ="alert(''Timeout Please Refresh Page!'')";
//ScriptManager.RegisterStartupScript(this,GetType(),"ServerControlScripts",strc,true);
}

}
其他
{
字符串col =:";
DateStampLabel.Text =(time1.Minutes.ToString())+ col +(time1.Seconds.ToString());
}


}
在此功能中,当页面一次又一次获得回发时,它将重置session的值.此值每次都是从数据表中绑定的,因此我只想设置一次会话值,然后使用它来进行页面是否回发.
谢谢

I working on online quiz program where i set the timer value according to my calucation :
protected void UpdateTimer_Tick(object sender, EventArgs e)
{
TimeSpan time1 = new TimeSpan();
time1 = (DateTime)Session["time"] - DateTime.Now;
if (time1.Minutes <= 0)
{
if (time1.Seconds <= 0)
{
// string strc = "alert(''Timeout Please Refresh Page!'')";
// ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScripts", strc, true);
}

}
else
{
string col = ":";
DateStampLabel.Text = (time1.Minutes.ToString()) + col + (time1.Seconds.ToString());
}


}
in this function when page get postback again and again it will reset the value of session .this value is bindind from the datatable every time so i just want to set the session value once and then use it whether page get postback or not .
Thanks

推荐答案

尝试:
if (!IsPostback)
   {
   ...
   }


这篇关于页面加载时如何仅一次初始化会话值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆