Solved

Web control contents not being preserved

Posted on 2004-09-01
3
302 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
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mail.To.Add 5 35
ASP.NET(C#) Eliminating weekends from a date range 2 46
Footer for each row on Gridview 2 33
Validating textboxes in red square borders. 2 17
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 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