2
votes

In my ASP.NET Web Forms application I have a download.aspx page paned layout. On the left pane I have a TreeView control and on the right pane I display some content once the user selects a leaf node.

If the user (not logged on) clicks on a leaf node of the TreeView which requires authorization, the user is sent to the login component and, after performing the login, it is redirected to the download.aspx with the TreeView not expanded.

I would like to change this behavior by redirecting the user (after the login) to the download page with the TreeView expanded as before s/he was sent to the login component.

I didn't design the page and I never use the TreeView extensively. My first guess, since I don't see any QueryString, is that the node expansion is managed by a JavaScript (or JScript) handler, that handles the onExpand event of the TreeView and asynchronously fetches the sub-nodes from the database. However I am not sure it works like that.

My idea is to create a Session State object Session["downloadTVdepth"] where, everytime the user expand a node, somehow I store the node(s) s/he has reached. So when there is a redirection from login component to downloads.aspx, the code checks whether there is the Session["downloadTVdepth"] value and eventuallty expands the tree.

Is my approach correct? How can I get the info about the TreeView node(s) that are expanded? How can I launch the onExpand event without the user actually expanding a node?

3

3 Answers

1
votes

What about setting a TreeNode.NavigateUrl for each TreeNode, then via url you can pass custom parameter.

string nodeText = ...;
string nodeId = ...;
var node = new TreeNode(nodeText, nodeId) 
   {
     NavigateUrl = String.Format("~/download.aspx?CurrentId={0}", nodeId);
   };

tree.Nodes.Add(node);

Then in a page's Page_Load() you can check Request.QueryString["CurrentId"] value.

If you are usig built in Forms Authenticalion you might find useful RedirectUrl feature, see this article for description with an example.

0
votes

It's very simple. Below, you can see my recursive version:

//List of storage ids of expanded nodes
List<int> expandedNodeIds = new List<int>();
//call recursive fun for our tree
CollectExpandedNodes(tree.Nodes);
//recursive fun for collect expanded node ids
private void CollectExpandedNodes(TreeListNodes nodes)
{
   foreach (TreeListNode node in nodes)
   {
      if (node.Expanded) expandedNodeIds.Add(node.Id);
      if (node.HasChildren) CollectExpandedNodes(node.Nodes);
   }
}