Solved

Web control contents not being preserved

Posted on 2004-09-01
3
304 Views
Last Modified: 2012-06-21
Maybe someone can help me with this problem:

I have a treeview in my detail.aspx (which runs in a frame) like so:

<wtv:TreeView id="docTree"             
      runat="server" NodeCssClass="MyNode"
      NodeImageUrlExpanded="images/FolderExpanded.gif"
      NodeImageUrl="images/Folder.gif"
      TemplateDataBinding="false" Animate="false"
      AutoPostBack="false"></wtv:TreeView>

Most of that is irrelevant but I want to be complete. In my .cs file, it is:

      public class detail : System.Web.UI.Page
      {
            protected PowerUp.Web.UI.WebTree.TreeView docTree;
            .....
      }

In Page_Load, I build the tree and add nodes. I have logic so I only do this once, I don't want to rebuild the tree every time. When this page is reloaded, which is always by a javascript call in another page:

      var theFrame = self.frames["detail"];    
      theFrame.location = "detail.aspx";

but although the treeview displays fine the first time, on every subsequent load of the page, the treeview.Nodes.Count==0  !! I know I am missing something important here, but I can't imagine what. Once I build the tree, the nodes should be preserved, it is a server control.
0
Comment
Question by:RichardFox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
shovavnik earned 500 total points
ID: 11954189
Server controls do not automatically preserve their values.  They need to be told to do so.

In addition, they usually preserve their values only on PostBacks, which are essentially "submits" to the same page.  Changing the url of the page does not cause a postback event.  You'll notice that the value of IsPostBack is always false in your code.

Furthermore, when server controls *do* preserve their values, it's because they *are* rebuilt.  By saying "preserve", the meaning is that they cache their data and then load it using a faster or more efficient method.

I think what you want to do is always rebuild the tree, but also always try to load the data from some cached location.  Sample code for getting the data:

... Page_Load() {
XmlDocument treeDoc = null;
// first try to get it from the session
object treeInSession = Session[ "TREE_DOCUMENT" ];
// check if the session is null - this indicates that you need to load the data from the database, or wherever
if( treeInSession == null ) {
  treeDoc = GetTreeXmlFromDataBase();
  // save it to the session so subsequent calls load it without the database
  Session[ "TREE_DOCUMENT" ] = treeDoc;
}
// if the session exists, then use that data
else {
  treeDoc = (XmlDocument) treeInSession;
}
// now bind your tree
MyTree.DataSource = treeDoc; // or whatever the name of the property is
}
0
 

Author Comment

by:RichardFox
ID: 11956219
That's exactly what I needed to know! You were abs. right, that IsPostBack is always false. THanks for the education.
0
 
LVL 8

Expert Comment

by:shovavnik
ID: 11956752
You're welcome.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question