Solved

IE TreeView reload issue with "Visual Inheritance"

Posted on 2004-09-15
22
285 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
ID: 12069621
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
ID: 12069641
Do you have the enableViewSate property of the treeveiw set to true?
0
 

Author Comment

by:sjd0103
ID: 12069748
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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:sjd0103
ID: 12074942
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
ID: 12168838
Hello...anything...anyone?
0
 

Author Comment

by:sjd0103
ID: 12178862
Experts...any advice?
0
 

Author Comment

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

Expert Comment

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

Author Comment

by:sjd0103
ID: 12189144
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
ID: 12189198
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
ID: 12189395
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
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12189422
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
ID: 12189527
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
ID: 12189538
then you'll want to use a javascript approach for that clientside functionality.
0
 

Author Comment

by:sjd0103
ID: 12297988
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
ID: 12298268
0
 

Author Comment

by:sjd0103
ID: 12298317
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
ID: 12298332
yw my friend;)
0
 

Author Comment

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

Expert Comment

by:AerosSaga
ID: 12421331
in this question?
0
 

Author Comment

by:sjd0103
ID: 12506803
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
ID: 12507006
Very happy I could help;)

Aeros
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

785 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