• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • Last Modified:

IE TreeView reload issue with "Visual Inheritance"

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
sjd0103
Asked:
sjd0103
  • 12
  • 10
1 Solution
 
AerosSagaCommented:
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
 
AerosSagaCommented:
Do you have the enableViewSate property of the treeveiw set to true?
0
 
sjd0103Author Commented:
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
Technology Partners: 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!

 
sjd0103Author Commented:
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
 
sjd0103Author Commented:
Hello...anything...anyone?
0
 
sjd0103Author Commented:
Experts...any advice?
0
 
sjd0103Author Commented:
Today will be the day!  I can feel it.
0
 
AerosSagaCommented:
how are you currently attempting to retain your treeveiw viewstate at postback?
0
 
sjd0103Author Commented:
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
 
AerosSagaCommented:
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
 
sjd0103Author Commented:
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
 
AerosSagaCommented:
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
 
sjd0103Author Commented:
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
 
AerosSagaCommented:
then you'll want to use a javascript approach for that clientside functionality.
0
 
sjd0103Author Commented:
I just can't see awarding points yet as no one has answered solved the problem or offered a solution that works.
0
 
AerosSagaCommented:
0
 
sjd0103Author Commented:
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
 
AerosSagaCommented:
yw my friend;)
0
 
sjd0103Author Commented:
I haven't abandoned this...just working on another issue...
0
 
AerosSagaCommented:
in this question?
0
 
sjd0103Author Commented:
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
 
AerosSagaCommented:
Very happy I could help;)

Aeros
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 12
  • 10
Tackle projects and never again get stuck behind a technical roadblock.
Join Now