Solved

IE TreeView reload issue with "Visual Inheritance"

Posted on 2004-09-15
22
283 Views
Last Modified: 2008-01-09
I have an asp.net (c#) application that I’m transforming to utilize “visual inheritance” by using the following template http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=27157AEF-7A64-466A-98F6-D93AF78C1547
as an example.  The concept is simple, but too complex to explain here.

I have the PageBase and SamplePageBase implemented.  My issue is that I’m utilizing the IE TreeView control and cannot get it to remain on each page with the appropriate node selected.

I’ve tried only loading the TreeView once on the initial entry into the application and not subsequent requests.  This causes the TreeView to only be visible on that initial page.  

Also, I’ve tried loading the TreeView on each page request and postback.  Doing this shows the TreeView, but it is collapsed with the first node selected each time I load a new page.  

I’ve tried catching the SelectedIndexChange event (to store and reset the selected node), but this is only firing when I expand or contract a node.  Clicking a child node results in a redirect to a new page with the URL being stored as a node attribute, but the SelectedIndexChange does not fire.

Feel free to request code examples or ask questions.  Thank you!
0
Comment
Question by:sjd0103
  • 12
  • 10
22 Comments
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
Check this tutorial concerning client side state management regarding the treeview contorl:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformstreeviewclassctortopic.asp

Regards,

Aeros
0
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
Do you have the enableViewSate property of the treeveiw set to true?
0
 

Author Comment

by:sjd0103
Comment Utility
Aeors...Thanks, but nothing helpful on that link.  I've been up and down MSDN.

I think this issue is more design related than TreeView specific.  

ViewState is enabled by default, but I set it explicitly just now and had the same results.
0
 

Author Comment

by:sjd0103
Comment Utility
Should I post this question to another topic area?  I can't believe it's that difficult.  Should I provide more info?  Is it the "Visual Inheritance" that's keeping everyone away?
0
 

Author Comment

by:sjd0103
Comment Utility
Hello...anything...anyone?
0
 

Author Comment

by:sjd0103
Comment Utility
Experts...any advice?
0
 

Author Comment

by:sjd0103
Comment Utility
Today will be the day!  I can feel it.
0
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
how are you currently attempting to retain your treeveiw viewstate at postback?
0
 

Author Comment

by:sjd0103
Comment Utility
Thank you for getting back into this AeorsSaga!

I'm setting "EnableViewState=true" in the page directive.

The problem is that the treeview is not retaining it's "state" at postback.  If I don't reload it, it doesn't appear.  If I do reload it, it's truly reloading and also not selecting the node that was just clicked.
0
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
well what if we tried to manually pass the state somehow with something like this:

so when your user posts back you can catch that event correct with something like this:
private void TreeView1_Expand( object sender ,  Microsoft.Web.UI.WebControls.TreeViewClickEventArgs e)
{
      string strConnectionString   = "data source=(local);" +
            "initial catalog=pubs;integrated security=SSPI";
      string strSQLTitles;
      SqlConnection cnn;
      SqlDataAdapter cmTitles;
      DataSet ds;
      TreeNode nodeTitle;
      TreeNode nodeAuthor;
      
        nodeAuthor = ((Microsoft.Web.UI.WebControls.TreeView)sender).Nodes[(int.Parse(e.Node))];
      if (nodeAuthor.Nodes.Count == 0)
      {
            //Create the Connection and the DataSet, and then open the connection.
            cnn = new SqlConnection(strConnectionString);
            ds = new DataSet();
            cnn.Open();

            //Add a Titles table to the DataSet.
            strSQLTitles = "SELECT titles.title FROM titles " +
                  "INNER JOIN titleauthor ON titles.title_id " +
                  "= titleauthor.title_id where titleauthor.au_id " +
                  "= '" + nodeAuthor.NodeData.ToString() +
                  "' ORDER BY titles.title";
            cmTitles = new SqlDataAdapter(strSQLTitles, cnn);
            cmTitles.Fill(ds, "Titles");

            foreach (DataRow rowTitle in ds.Tables["Titles"].Rows)
            {
                  nodeTitle = new TreeNode();
                  nodeTitle.Text = rowTitle["Title"].ToString();
                  nodeAuthor.Nodes.Add(nodeTitle);
            }

            //Clean up.
            ds.Dispose();
            cmTitles.Dispose();
            cnn.Close();
            cnn.Dispose();
      }
      
}

so what if somehow you created a new sql command based on what they expand, save it to like a session variable, then on postback you could rebind the treeview using the sql command you stored in session.  Just trying to get things movin here.
Let me know if that gives you any ideas.

Aeros                  

0
 

Author Comment

by:sjd0103
Comment Utility
I think the problem is that when a navigational node is clicked it is not considered a postback since there is one base class and one base control -- "layout" control shown here:

<body leftMargin="0" topMargin="0" MS_POSITIONING="GridLayout">
<form id="frmLayout" method="post" runat="server">
<table height="100%" cellSpacing="0" cellPadding="0" width="100%" border="0">
      <tr valign=top>
            <td width=20%><uc4:navigator id="uctNavigator" runat="server"></uc4:navigator></td>
            <td width=80%>
                  <table height=100% cellspacing=0 cellpadding=0 width=100% border=0>
                        <tr>
                              <td>
                                    <uc3:header id="uctSectionHeader" runat="server"></uc3:header>
                              </td>
                        </tr>
                        <tr vAlign="top" height="100%">
                              <td align="center"><asp:placeholder id="Content" runat="server"></asp:placeholder></td>
                        </tr>
                  </table>
            </td>
      <tr valign=bottom>
            <td colSpan="2"><uc2:footer id="Footer" runat="server"></uc2:footer></td>
      </tr>
</table>
</form>

My "uctNavigator" contains the offending TreeView.  I'm loading all nodes (it's relatively small and expanded by default) on page_load of the uctNavigator.  I am doing a !Page.IsPostBack check before loading the TreeView, but that doesn't matter since it looks like a new page_load when the navigation is to another page.  

Does that make sense?  The functionallity is doing what it should, but I'm missing a way to keep the TreeView from having to reload everytime another node is selected.  My guess is that my solution will lie in the base class that is inheriting the System.Web.UI.Page (and is inherited by each of the pages that the TreeView navigates to.

Hopefully I didn't drive you away again, Aeros.  I do appreciate your input!
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
you have to forumulate a way to caputure what select statements you need to reload the treeview in the same state as it was before postback.  Thats what I was alluding to in my previous post.
0
 

Author Comment

by:sjd0103
Comment Utility
So, what you're saying is that you do not know how to keep the tree's selected value between node clicks without reloading each time?

My solution here can not be to reload the tree each time.  Thanks for getting things moving though.  Please let me know if you think of something else.
0
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
then you'll want to use a javascript approach for that clientside functionality.
0
 

Author Comment

by:sjd0103
Comment Utility
I just can't see awarding points yet as no one has answered solved the problem or offered a solution that works.
0
 
LVL 17

Accepted Solution

by:
AerosSaga earned 500 total points
Comment Utility
0
 

Author Comment

by:sjd0103
Comment Utility
This may hold the key (excitement building).  I have a prod issue to take care of until Friday.  I'll get back to you on Monday.  Thank you!
0
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
yw my friend;)
0
 

Author Comment

by:sjd0103
Comment Utility
I haven't abandoned this...just working on another issue...
0
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
in this question?
0
 

Author Comment

by:sjd0103
Comment Utility
Moving on to another issue.  Thanks AerosSaga for your time!  I have not had time like I thought I would to resolve this one.
0
 
LVL 17

Expert Comment

by:AerosSaga
Comment Utility
Very happy I could help;)

Aeros
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

772 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

10 Experts available now in Live!

Get 1:1 Help Now