I am building an intranet application for my company to manage departments and employees. It has a masterpage with the menu and some authentication code.
I load it recursively from an SQL database. It takes about 30 seconds or more to load and display (it is 4 or 5 levels deep, has about 60 departments and 500 employees).
So far, I came up with the approach to save the whole treeview in a session variable and when the user visits a page that has this treeview, if it exists in the session variables, I load it from there, if not, I load it from the database and put it in the session variables as well. I was wonderring if this is a good method to do it or not, especially since I noticed that after I retrieve the treeview for the frst time from the session variables, it seems to dissapear from there, so I have to put it back after each retrieval. This gives me the odd feeling that I may not properly understand what is going on.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["SessionStoredTreeView"] == null)
{
RecursivelyLoarTreeView(); //takes 30 seconds
Session["SessionStoredTreeView"] = TreeViewOnPage;
}
else
{
TreeView tv = (TreeView)Session["SessionStoredTreeView"];
TreeViewOnPage.Nodes.Clear();
TreeViewOnPage.Nodes.Add(tv.Nodes[0]);
Session["SessionStoredTreeView"] = TreeViewOnPage;
}
}
}
Try caching some parts of your page or user control :
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.