【发布时间】:2012-03-02 03:33:45
【问题描述】:
我有一个面板 (pnlPanel),其中包含许多控件,例如 Textboxes and DropDownLists。我希望它们在用户返回页面时保持不变,所以我尝试了这个:
/*i have saved the panel like this
Session["testPanel"] = pnlTest;
*/
protected void Page_Load(object sender, EventArgs e)
{
if (Session["testPanel"] != null)
{
panel = Session["testPanel"] as Panel;
}
}
但它不起作用。可能吗?我之所以要这样做是因为开销不是问题,并且我想减少编码时间。
【问题讨论】:
-
你试过
panel = (Panel)Session["testPanel"];吗?另外,你的表达方式是Session["panel"],这会导致错误。 -
您可能需要考虑 ASP.NET 用户控件缓存。如果将面板代码移动到用户控件中,则可以轻松缓存呈现的内容。 stackoverflow.com/questions/880937/…
-
面板包含文本框和下拉列表。