问题描述
我有一个问题,就是当我们在页面上进行工作时,会话时间会提醒用户,而我们希望页面处于空闲状态时意味着页面上没有工作,那么会话时间应该警告用户.这样做吗??
感谢您的帮助...
i have a problem that is when we are doing work on a page then session time alert the user,while we want when the page is in idle condition means there is no working on page,then session time should be warn the user.How to do this????
Thanks for help...
推荐答案
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class ajaxtimer : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
hid_Ticker.Value = new TimeSpan(0, 0, 0).ToString();
}
}
protected void Timer1_Tick(object sender, EventArgs e)
{
hid_Ticker.Value = TimeSpan.Parse(hid_Ticker.Value).Add(new TimeSpan(0, 0, 1)).ToString();
lit_Timer.Text = "Time spent on this page: " + hid_Ticker.Value.ToString();
if (hid_Ticker.Value == "00:00:15")
{
Response.Redirect("http://"+fld_Name.Text);
}
}
protected void btn_Submit_Click(object sender, EventArgs e)
{
lit_Name.Text = "Thanks. You are redirected to: " + fld_Name.Text;
}
}
function Timeout()
{
//have hardcoded the session timeout below..u can get it from code behind
window.setTimeout(DisplayWarning,90000-12000)//this will display warning after 13 min from page load
}
function DisplayWarning()
{
//display ur warning here
var newwindow =window.open( "warning.aspx", "WarningTitle", "channelmode=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=330,height=220", true);
newwindow.focus();
Timeout();
}
在每个页面上导入此js ..并在onload上调用Timeout()函数,如..< body onload ="Timeout();"> ...在这里,您可以想到更好的解决方案,例如从一个实例调用timeout函数常见的地方..例如,有一些父类
在warning.aspx页面中,添加以下代码
Import this js on every page..and call Timeout() function on onload like ..<body onload="Timeout();">...here u can think of a better solution like calling the timeout function from one common place ..ex.having some parent class
In warning.aspx page add below code
function CloseWindow()
{
var bclicked = "<%=bclicked%>";
if(bclicked == "True" || bclicked == "true" )
{
window.close();
}
}
在onload上调用此CloseWindow()函数,如<body onload="CloseWindow();">
并且在代码背后的代码中应该是..
Call this CloseWindow() function on onload like <body onload="CloseWindow();">
and In code behind the code shud be..
public bool bclicked = false;
protected void Page_Load(object sender, EventArgs e)
{
bclicked = false;
}
protected void Button1_Click(object sender, EventArgs e)
{
bclicked = true;
}
这篇关于会话超时时提醒用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!