由于UpdatePanel,我遇到了问题。我从后面的代码分配Windows超时(片段在页面加载)。第一次正确分配时间。但是当我更改下拉列表或其他导致页面加载的控件时,不会分配时间。但是我希望每当发生页面加载时都会重置会话时间。
<script language="javascript" type="text/javascript">
alert(<%=mintTimeout%>);
window.setTimeout("endSession();",<%=mintTimeout%>);
function endSession()
{
alert("Your session has expired. You will be redirected to the login page.");
}
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="true">
<asp:ListItem>a</asp:ListItem>
<asp:ListItem>b</asp:ListItem>
<asp:ListItem>c</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
我背后的代码是
public int mintTimeout = 0;
protected void Page_Load(object sender, EventArgs e)
{
Session.Timeout = 1;
mintTimeout = (Session.Timeout) * 60000;
}
protected void Button1_Click(object sender, EventArgs e)
{
}
请帮助我解决这个问题?
答案 0 :(得分:1)
您需要清除并重新分配每个回发的超时。您可以使用pageLoad
功能。更改您的脚本如下:
var sessionExpiredTimeout = null;
function pageLoad() {
if(sessionExpiredTimeout){
clearTimeout(sessionExpiredTimeout);
}
sessionExpiredTimeout = setTimeout(endSession, <%= mintTimeout %> );
}
function endSession() {
alert("Your session has expired. You will be redirected to the login page.");
}