我有一个很长的进程循环,在运行时我希望使用ajax或jquery在文本框或标签中显示更新的值,我尝试添加事件计时器并在运行循环时将值设置为Session,但是它不起作用它显示时间而不是会话的新值
在aspx文件中
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Timer ID="timer1" runat="server"
Interval="1000" OnTick="timer1_tick"></asp:Timer>
</div>
<div>
<asp:UpdatePanel id="updPnl"
runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblTimer" runat="server"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="timer1" EventName ="tick" />
</Triggers>
</asp:UpdatePanel>
</div>
在aspx.cs文件中
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["timeout"] = DateTime.Now.AddSeconds(2000);
}
}
protected void timer1_tick(object sender, EventArgs e)
{
TimeSpan time1 = new TimeSpan();
time1 = (DateTime)Session["timeout"] - DateTime.Now;
if (time1.Seconds <= 0)
{
lblTimer.Text = "TimeOut!";
}
else
{
lblTimer.Text = Session["test"].ToString() + " " + time1.Seconds.ToString();
}
}
此值Session [“test”]。在长过程循环的每次迭代中,ToString()都更新为新值。任何帮助!!!