2014-01-14 60 views
0

我正在研究具有許多頁面上使用的類似功能的應用程序。我有一個打開模式窗口並允許用戶進行搜索的屏幕。當用戶點擊記錄時,記錄名稱首先保存在一個會話中,然後要求父窗口關閉該模式,然後進行刷新。在頁面加載到一個頁面之前會丟失會話,但不會在另一個頁面上丟失會話

然後在父頁的加載情況下,我會檢查查看搜索文本會話的值是什麼,然後我使用它來搜索其他數據並填充屏幕。

這個設置在我開發的第一個屏幕上工作正常,並且沒有失敗過一次。問題是,在我以完全相同的方式設置的另一個屏幕上,在父窗口的頁面加載時檢查會話值時,它被設置爲NULL,我甚至從工作中複製了相同的代碼頁面,所以它應該是相同的。

子窗口JS:

<script type="text/javascript"> 
     function sendval() { 
      window.parent.onSave(); - Just switches off a checkdirty function. 
      window.parent.location.reload(); - Reloads the parent so it can get the val on page load 
     } 
     </script> 

子窗口按鈕:

<asp:Button ID="Button1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "AddressCode") %>' OnClientClick="sendval();" OnClick="Button1_Click" /> 

子窗口按鈕方法:

用於會話值
protected void Button1_Click(object sender, EventArgs e) 
{ 
    string buttonText = ((Button)sender).Text; 
    Session["CustTypeVal"] = buttonText; 
} 

父窗口校驗(這是其中會話在一頁上返回爲空而在另一頁上不爲空:

protected void Page_Load(object sender, EventArgs e) 
      { 
//get the session variable from the open page in order to do the search. 
       if (Session["CustTypeVal"] != null) 
       { 
        //The method you need to run after refresh 
        SearchInvAddr((string)Session["CustTypeVal"]); 
        //Remove the session after 
        Session.Remove("CustTypeVal"); 
       } 
} 

我希望對此有幫助。

+0

是否有更多的代碼可供分享?我在下面添加了我的回覆,但更多代碼對於更全面地回答您的問題會有所幫助。沒有正確讀取Session值的頁面的代碼會很有幫助。 – dgarbacz

回答

1

你的代碼在這裏

protected void Page_Load(object sender, EventArgs e) 
      { 
//get the session variable from the open page in order to do the search. 
       if (Session["CustTypeVal"] != null) 
       { 
        //The method you need to run after refresh 
        SearchInvAddr((string)Session["CustTypeVal"]); 
        //Remove the session after 
        Session.Remove("CustTypeVal"); 
       } 
} 

如果這是你的第一頁,你必須在第二頁上完全相同的代碼,會話值不再會存在,因爲

Session.Remove("CustTypeVal"); 

如果您使用會話值,則在登出之前不必清除它們,因此除非可能用於違反安全性,否則不需要將其刪除。

相關問題