2011-08-24 54 views
1

我有一個問題:在我的項目我有一個LinkBut​​ton其執行以下操作:會話變量,餅乾和UpdatePanel的Load事件

Response.Cookies("synthetic_fm_user_session")("session_id") = String_Session_Id 
Response.Cookies("synthetic_fm_user_session").Expires = DateTime_Session_Stop 

Session("Integer_User_Id") = Integer_User_Id 

UpdatePanel.Update() 

我的UpdatePanel Load事件看起來像這樣:

If Not Request.Cookies("synthetic_fm_user_session") Is Nothing Then 

    Panel1.Visible = True 

End If 

If Not Session("Integer_User_Id") Is Nothing Then 

    Panel2.Visible = True 

End If 

然後,當我點擊這個LinkBut​​ton,它將會話變量和Cookies設置爲某個值(Not Nothing)並更新UpdatePanel Load事件中的UpdatePanel時,會話變量和Cookie仍然沒有!並在第二個UpdatePanel.Update()會話變量和餅乾變得不是什麼!

爲什麼會發生,以及如何解決它?

+0

是否已進行了肯定被寫入的值不是什麼都沒有? – StefanE

+0

因爲我有。 –

回答

1

UpdatePanel的Load事件僅在頁面加載時執行。運行UpdatePanel.Update()將不會再次執行加載事件。

看起來你應該有一個單獨的函數來設置更新面板的知名度和執行,而不是在UpdatePanel.Update頁面Load事件

+0

但在我的項目中,我必須在每個UpdatePanel.Update()上執行一些函數。可能嗎?我應該使用哪個事件? –

+0

創建您自己的「事件」,它將執行您的所有代碼,然後創建您在該函數中調用UpdatePanel.Update()的最後一件事。您直接使用這個新函數而不是UpdatePanel.Update()。 – StefanE

+0

感謝您的回覆!我會盡力這樣做! –