0
我有一個asp.net網站,它需要登錄並保存到會話中的類。當會話過期(或者當我清除它時),我需要用戶再次登錄,但最好不要返回到主登錄頁面(因爲用戶丟失了他們輸入的所有內容)。OnInit打開模式對話框兩次
在主頁OnInit上,我檢查會話是否爲空,如果是,它們會被註銷。我在我的母版頁上創建了一個jquery模式對話框,它接收登錄信息並在有效登錄時重新創建會話。
然而,這個對話框會在他們登錄後關閉對話框(此時會話不爲空),然後再次打開。
我已經嘗試在登錄過程中設置不同的會話值,所以它不會打開模式對話框,但它不會看到它並打開它(並且看到登錄會話爲空,即使它不是。
x'ing出對話框,一切都很好。
有人可以告訴我,我要去哪裏錯或如何防止對話框打開,從兩次?
碩士頁碼:
<script type="text/javascript">
function showloginpopup() {
$("#popuplogin").dialog({
resizable: false,
width: 320,
height: 310,
modal: true,
// dialogClass: "no-close", // adding this would remove the x button
appendTo: "form",
buttons: {
}
});
};
</script>
<asp:UpdatePanel ID="upLogin" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div id="popuplogin" style="display: none;" class="ticker" title="Login">
<asp:Panel ID="pnlWorkArea" runat="server" CssClass="login_workarea_panel" DefaultButton="btnLogin">
<%-- textboxes and btnLogin for logging in --%>
</asp:Panel>
</div>
</ContentTemplate>
</asp:UpdatePanel>
btnLogin讀取文本框並用用戶信息填充我的會話。
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (Classes.LoggedInUser.Current.loggedInUser == null) // This is returning null on 2nd time even though after first time it is set
{
ScriptManager.RegisterStartupScript(this, GetType(), "Show Login Popup", "showloginpopup();", true);
loadData(); // Populate some buttons based on permissions from login
}
}
謝謝!
我建議的是,你可以使用另一個會話或查詢字符串,同時打開彈出窗口作爲標誌,一旦它打開標誌它是真實的,所以另一次當它的真實,該彈出窗口不會顯示,(注意這是不是真的很好的方式,因爲你正在創建新的會話,可能需要很多內存只是爲了這個目的,但我建議不考慮內存使用的問題。:)) –
我試過這個 if(Classes.LoggedInUser。 Current.loggedInUser == null && Session [「_ mylogin_」] == null) - 然後設置會話,然後在登錄時重置爲空 - 沒有任何區別:| 幾乎就好像對話已決定在會話設置之前第二次打開 –
不是問題,您是否調試過並在「loggedInUser」中檢查登錄成功後得到的是什麼,如果我沒有比「loggedInUser」是一個類的常量(它可能是系統安全類,不),但是我堅持直接檢查Session [「MyLogin」]。Tostring()== NULL && Session [「MyLogin」]。Tostring()==「 「(它總是很好地檢查空白。) –