我希望會話超時在單擊模式彈出窗口的「是」按鈕時重置。目前JavaScript代碼只是隱藏Modal彈出窗口。其他一切都在按照應有的方式工作。由於單擊模式彈出窗口的「是」按鈕時重置會話超時
HTLML代碼
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<h3>Session Idle: <span id="secondsIdle"></span> seconds. </h3>
<asp:LinkButton ID="lnkFake" runat="server" />
<asp:ModalPopupExtender ID="mpeTimeout" BehaviorID ="mpeTimeout" runat="server" PopupControlID="pnlPopup" TargetControlID="lnkFake"
OkControlID="btnYes" CancelControlID="btnNo" BackgroundCssClass="modalBackground" OnOkScript = "ResetSession()">
</asp:ModalPopupExtender>
<asp:Panel ID="pnlPopup" runat="server" CssClass="modalPopup" Style="display: none">
<div class="header">
Session Expiring!
</div>
<div class="body">
Your Session will expire in <span id="seconds"></span> seconds.<br />
Do you want to reset?
</div>
<div class="footer" align="right">
<asp:Button ID="btnYes" runat="server" Text="Yes" CssClass="yes" />
<asp:Button ID="btnNo" runat="server" Text="No" CssClass="no" />
</div>
我想的JavaScript代碼來處理目前對話重置代碼只是隱藏模式彈出
JavaScript代碼
<script type="text/javascript">
function SessionExpireAlert(timeout) {
var seconds = timeout/1000;
document.getElementsByName("secondsIdle").innerHTML = seconds;
document.getElementsByName("seconds").innerHTML = seconds;
setInterval(function() {
seconds--;
document.getElementById("seconds").innerHTML = seconds;
document.getElementById("secondsIdle").innerHTML = seconds;
}, 1000);
setTimeout(function() {
//Show Popup before 20 seconds of timeout.
$find("mpeTimeout").show();
}, timeout - 20 * 1000);
setTimeout(function() {
window.location = "Login.aspx";
}, timeout);
};
function ResetSession() {
// Hide Modal Popup
$find('mpeTimeout').hide();
// Reset Session Here
}
</script>
C#代碼
protected void Page_Load(object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
if (this.IsPostBack)
{
Session["Reset"] = true;
Configuration config = WebConfigurationManager.OpenWebConfiguration("~/Web.Config");
SessionStateSection section = (SessionStateSection)config.GetSection("system.web/sessionState");
int timeout = (int)section.Timeout.TotalMinutes * 1000 * 60;
ClientScript.RegisterStartupScript(this.GetType(), "SessionAlert", "SessionExpireAlert(" + timeout + ");", true);
}
}
使用jQuery/AJAX。爲什麼回傳? –
@ T.S任何代碼建議請 –
我給你的想法 - 谷歌是充滿了這些東西(代碼)。在aspx頁面中創建web方法,並使用Ajax包裝器之一調用它(jQuery是一個有據可查的開源js庫)。 –