Solved

Web control contents not being preserved

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Asp.net mvc foreach 3 35
What .NET URL re-routing tool did I use? 2 38
Adware on IIS hosted asp.net website 1 20
ASP.net show message while code is running 3 11
Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now