请原谅我问了一个平凡的新手问题,但我似乎陷入了课堂生命周期的困境。
所以我有我的页面
public partial class DefaultPage : BasePage
{
...
}
BasePage 是这样的:
public class BasePage : System.Web.UI.Page
{
private Model _model;
public BasePage()
{
if (ViewState["_model"] != null)
_modal = ViewState["_model"] as Modal;
else
_modal = new Modal();
}
//I want something to save the Modal when the life cycle ends
[serializable]
public class Model
{
public Dictionary<int, string> Status = new Dictionary<int, string>();
... //other int, string, double fields
}
public class PageManager()
{ //code here; just some random stuff
}
}
现在我只想在页面加载时获取 Modal,这是我从构造函数中完成的。如何在页面卸载时保存它?我不能使用析构函数,因为它不可靠。
这种情况的最佳解决方案是什么?
谢谢。