Moderator.. this is for the 'CSS Friendly Control Adapter' forum. I posted this earlier and it was posted to 'Master Pages, Themes and Navigation controls':
http://forums.asp.net/thread/1411894.aspx
I have discovered several problems with the treeview adapter.
First, NodeCheckChanged event is refired for every node that is checked in every postback. I created a fix that involves creating a postbackeventreference in the BuildItem method of the TreeViewAdapter.cs file:
To capture the event, I added the following code to the RaisePostBackEvent:
if (eventArgument != null)
{
if (eventArgument.StartsWith("s") || eventArgument.StartsWith("e"))
{
string selectedNodeValuePath = eventArgument.Substring(1).Replace("\\", "/");
TreeNode selectedNode = treeView.FindNode(selectedNodeValuePath);
if (selectedNode != null)
{
bool bSelectedNodeChanged = selectedNode != treeView.SelectedNode;
selectedNode.Selected = true; // does not raise the SelectedNodeChanged event so we have to do it manually (below).
ExpandToSelectedNode();
if (eventArgument.StartsWith("e"))
{
selectedNode.Expanded = true;
}
if (bSelectedNodeChanged)
{
Extender.RaiseAdaptedEvent("SelectedNodeChanged", new EventArgs());
}
}
}
else if (eventArgument.StartsWith("p"))
{
string parentNodeValuePath = eventArgument.Substring(1).Replace("\\", "/");
TreeNode parentNode = treeView.FindNode(parentNodeValuePath);
if ((parentNode != null) && ((parentNode.ChildNodes == null) || (parentNode.ChildNodes.Count == 0)))
{
ExpandToNode(parentNode);
parentNode.Expanded = true; // Raises the TreeNodePopulate event
}
}
else if (eventArgument.StartsWith("c"))
{
string parentNodeValuePath = eventArgument.Substring(1).Replace("\\", "/");
TreeNode parentNode = treeView.FindNode(parentNodeValuePath);
if (parentNode != null)
{
Extender.RaiseAdaptedEvent("TreeNodeCheckChanged", new TreeNodeEventArgs(parentNode));
}
}
I then commented out the the RaiseAdaptedEvent line in the UpdateCheckmarks method:
if (item.Checked != bIsNowChecked) { item.Checked = bIsNowChecked; // Adding postback support for checkmarks //Extender.RaiseAdaptedEvent("TreeNodeCheckChanged", new TreeNodeEventArgs(item)); }
That line was the cause of the TreeNodeCheckChanged event firing for every checked node.
The second problem I found is the TreeViewAdapter doesn't raise events properly if the treeview is in a webcontrol. This is due to how the RaiseAdapterEvent was created..
I did some basic testing and it looks like referencing the parent works a lot better than referencing the page.
The last problem I have figured out yet.. but it is easy to reproduce. I can't get nodes to expand in some of the demos. For example go here: http://www.asp.net/CSSAdapters/TreeView.aspx
Change the theme to 'Enhanced', then try to expand a node. The nodes won't expand.
Wow, I can't wait to study your ideas in more detail. I expect to do so tomorrow.
Meanwhile, I wanted to immediately answer your question regarding the problem with expanding the tree in the Enhanced them in the demo page you mentioned,
http://www.asp.net/CSSAdapters/TreeView.aspx.
Yes, that's on my to-do list to fix. The problem stems from the lack of position:relative in a few spots in the CSS for the TreeViewExample.css file in the Enhanced them folder... though it is actually more complicated then is sounds because you have to
use great care when adding position:relative in that file!
You actually CAN expand the nodes in the tree. You need to move your cursor just slightly to the LEFT of the plus/minus sign on the expandable tree nodes. Give it a try.
I'll write back when I've studied your other comments more. I'm already hip deep in TreeView adapter code as you may have noticed from previous postings. Thanks for the contribution.
There is a pretty simple fix for this. I'm leaning towards using it in the next rev of the kit... unless I hear from people that there is a problem with it.
<div>Find the 2 rules involving AspNet-TreeView-Collapse and AspNet-TreeView-Expand.</div>
<div>To each of these 2 rules, add the following:
font-family: Courier;
font-size: xx-large;
line-height: 20px;</div>
I've tested this fix in IE6, FF 1.5.0.7, Netscape Nav 8.1 and Opera 9.02. They all seem fine.
I'm still planning on replying in more detail to Brian's original suggestions for enhancing/modifying/fixing the TreeView expander. I just need a bit more time. Regards,
... starting to now look into Brian's original suggestions for changes to the TreeView adapter. I very much like the idea of using Parent rather than Page in the RaiseAdaptedEvent method. I've already integrated that into the code for the next rev. Good
just, Brian, spotting that and coming up with a good fix.
The issue concerning improper raising of the TreeNodeCheckChanged event is going to take a bit more thought. I have no doubt that your proposed solution will work in some cases... but it is going to conflict with other improvements planned for the TreeView.
See, http://forums.asp.net/thread/1393678.aspx. That thread involves improving the TreeView (in part, by using the client-side onclick event for the checkbox) to cascade checkbox settings up/down the tree. So, I'd prefer
to avoid setting the onclick handler on the client to handle the change event on the server. Instead, I'd like to figure out how we can use (and perhaps add to) the viewstate info after postback to figure out what was and wasn't checked previously compared
to what is and isn't checked upon postback in order to issue raise the events appropriately.
Let me know what you think. I'll post back here when I've got a more developed solution to propose to handle the TreeNodeCheckChanged problem. Again, thanks for the Page v. Parent fix in RaiseAdaptedEvent. Regards,
... regarding the TreeNodeCheckedChanged event... Brian (and others who are running into this) it's very important that you review these notes,
http://forums.asp.net/thread/1393604.aspx.
You MUST use the implementation pattern suggested in those notes. That is, if you are using the adapted TreeView you should be setting OnAdaptedTreeNodeCheckChanged in your <asp:TreeView>. Do not try to use the normal OnTreeNodeCheckChanged attribute.
Brian, were you aware of that? I know that chunk of information is buried at the moment. It will be made much more prominent in kit's real documentation in the next rev. Sorry if you ran afoul of it.
Right.. However removing the traditional OnTreeNodeCheckChanged attribute didn't keep the event from firing repeatedly for every checked node on every postback. I was originally posting about 3 problems until I realized that you were NOT supposed to have
the OnAdapted attributes AND the traditional attributes definied.
Actually, I think I was wrong with my last comment. Even if you have both OnTreeNodeCheckChanged and OnAdaptedTreeNodeCheckChanged (i.e., you have both the OnAdapted--- and the On--- version of the event handler) I don't think you should see them called
in a duplicate fashion. Only one or the other should be being called.
I have been working on the TreeView adapter (for the next rev) a tremendous amount lately and have looked for this duplicate event invokation in the debugger, etc. I don't see it with my files.
Is there any way for you to create a very simple and complete test recipe that I can use to try to dup the problem here?
It is very easy to reproduce the problem with the CheckChanged event firing for ever cheked node on every postback. Just add a button to the WalkThru/CheckboxTreeView.aspx provided in the adapter downloads. Check a couple of the nodes and click the button.
You will see the checkchanged event fire for each node that is checked. The checked state is remembered after the postback. Click the button again and the checkchanged event will fire again for each checked node even though their checked state was not changed.
Just got back from the veggie garden and started digging into this... I have good news on several fronts.
First, and most immediately, I was able to duplicate the problem using Brian's latest recipe. The safest and most immediate fix for you is (happily) quite easy. Go to this posting,
http://forums.asp.net/1/1397908/ShowThread.aspx. Locate my posting 09-12-2006, 5:33 PM. Cut-n-paste the code I posted there to create a version of the TreeViewAdapter.cs file in your site's App_Code\Adapters. (If
you are using VB you may need to do a little conversion work. There are some nice online converters but you still need to do some hand tweaking afterwards. If you are using VB and are really stuck, let me know and I'll try to help.)
Note that there are other ideas discussed on
http://forums.asp.net/1/1397908/ShowThread.aspx that some of you might want to explore but getting them integrated isn't as easy as the simple cut-n-paste recipe I just offered. Still, there are some great ideas there from others in the community.
OK, the other piece of good news is that all of these fixes will be included in the next rev of the kit so what you're struggling with now won't last forever. I apologize, though, for the immediate inconvenience. I'm working on other improvements to the
TreeView adapter (like maintaining the true and complete expand/collapse state between postbacks) so your patience will be rewarded.
If the fix at http://forums.asp.net/1/1397908/ShowThread.aspx does not solve your problem (i.e., if you continue to see events being fired inappropriately and too often) let me know. My testing locally showed that
applying the fix in http://forums.asp.net/1/1397908/ShowThread.aspx made this problem (which I could repro prior to applying the fix) go away. If your results vary from that... let me know.
Russ I am having this exact problem. In trying to fix it I attempted using your rewritten TreeViewAadapter from 09-12-2006, 5:33 PM to no avail. I believe that I am using the most recent rev of the adapters but, more than likely I am missing something
very simple here. Any help would be greatly appreciated.
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
This can be beneficial to other community members reading the thread.
brian.brown
Member
25 Points
5 Posts
TreeView adapter problem
Sep 27, 2006 10:30 PM|LINK
Moderator.. this is for the 'CSS Friendly Control Adapter' forum. I posted this earlier and it was posted to 'Master Pages, Themes and Navigation controls': http://forums.asp.net/thread/1411894.aspx
I have discovered several problems with the treeview adapter.
First, NodeCheckChanged event is refired for every node that is checked in every postback. I created a fix that involves creating a postbackeventreference in the BuildItem method of the TreeViewAdapter.cs file:
if (((item.ShowCheckBox != null) && (item.ShowCheckBox.Value == true)) || (treeView.ShowCheckBoxes == TreeNodeTypes.All) || ((treeView.ShowCheckBoxes == TreeNodeTypes.Leaf) && (!IsExpandable(item))) || ((treeView.ShowCheckBoxes == TreeNodeTypes.Parent) && (IsExpandable(item))) || ((treeView.ShowCheckBoxes == TreeNodeTypes.Root) && (item.Depth == 0))) { writer.WriteBeginTag("input"); writer.WriteAttribute("type", "checkbox"); writer.WriteAttribute("id", treeView.ClientID + "n" + _checkboxIndex.ToString() + "CheckBox"); writer.WriteAttribute("name", treeView.UniqueID + "n" + _checkboxIndex.ToString() + "CheckBox"); if (item.Checked) { writer.WriteAttribute("checked", "checked"); } // Add event for checkchanged writer.WriteAttribute("onclick", Page.ClientScript.GetPostBackEventReference(treeView, "c" + (Page.Server.HtmlEncode(item.ValuePath)).Replace("/", "\\"), true)); writer.Write(HtmlTextWriter.SelfClosingTagEnd); _checkboxIndex++; }To capture the event, I added the following code to the RaisePostBackEvent:
I then commented out the the RaiseAdaptedEvent line in the UpdateCheckmarks method:
if (item.Checked != bIsNowChecked)
{
item.Checked = bIsNowChecked;
// Adding postback support for checkmarks
//Extender.RaiseAdaptedEvent("TreeNodeCheckChanged", new TreeNodeEventArgs(item));
}
That line was the cause of the TreeNodeCheckChanged event firing for every checked node.
The second problem I found is the TreeViewAdapter doesn't raise events properly if the treeview is in a webcontrol. This is due to how the RaiseAdapterEvent was created..
The Page references cause the code to fail as the method delegate is in a control and not page. I fixed this by changing the code to:I did some basic testing and it looks like referencing the parent works a lot better than referencing the page.
The last problem I have figured out yet.. but it is easy to reproduce. I can't get nodes to expand in some of the demos. For example go here:
http://www.asp.net/CSSAdapters/TreeView.aspx
Change the theme to 'Enhanced', then try to expand a node. The nodes won't expand.
Treeview cssadapter treeview checkbox "css friendly adapter" checkbox
Russ Helfand
Contributor
3304 Points
744 Posts
Re: TreeView adapter problem
Sep 28, 2006 01:46 AM|LINK
Hi Brian,
Wow, I can't wait to study your ideas in more detail. I expect to do so tomorrow.
Meanwhile, I wanted to immediately answer your question regarding the problem with expanding the tree in the Enhanced them in the demo page you mentioned, http://www.asp.net/CSSAdapters/TreeView.aspx.
Yes, that's on my to-do list to fix. The problem stems from the lack of position:relative in a few spots in the CSS for the TreeViewExample.css file in the Enhanced them folder... though it is actually more complicated then is sounds because you have to use great care when adding position:relative in that file!
You actually CAN expand the nodes in the tree. You need to move your cursor just slightly to the LEFT of the plus/minus sign on the expandable tree nodes. Give it a try.
I'll write back when I've studied your other comments more. I'm already hip deep in TreeView adapter code as you may have noticed from previous postings. Thanks for the contribution.
Groovybits.com
Russ Helfand
Contributor
3304 Points
744 Posts
Re: TreeView adapter problem
Sep 28, 2006 07:00 PM|LINK
... more information about the problem expanding/contracting the tree nodes in the Enhanced sample page, http://www.asp.net/cssadapters/treeview.aspx
There is a pretty simple fix for this. I'm leaning towards using it in the next rev of the kit... unless I hear from people that there is a problem with it.
font-family: Courier;
font-size: xx-large;
line-height: 20px;</div>
I've tested this fix in IE6, FF 1.5.0.7, Netscape Nav 8.1 and Opera 9.02. They all seem fine.
I'm still planning on replying in more detail to Brian's original suggestions for enhancing/modifying/fixing the TreeView expander. I just need a bit more time. Regards,
Groovybits.com
Russ Helfand
Contributor
3304 Points
744 Posts
Re: TreeView adapter problem
Sep 28, 2006 08:33 PM|LINK
... starting to now look into Brian's original suggestions for changes to the TreeView adapter. I very much like the idea of using Parent rather than Page in the RaiseAdaptedEvent method. I've already integrated that into the code for the next rev. Good just, Brian, spotting that and coming up with a good fix.
The issue concerning improper raising of the TreeNodeCheckChanged event is going to take a bit more thought. I have no doubt that your proposed solution will work in some cases... but it is going to conflict with other improvements planned for the TreeView. See, http://forums.asp.net/thread/1393678.aspx. That thread involves improving the TreeView (in part, by using the client-side onclick event for the checkbox) to cascade checkbox settings up/down the tree. So, I'd prefer to avoid setting the onclick handler on the client to handle the change event on the server. Instead, I'd like to figure out how we can use (and perhaps add to) the viewstate info after postback to figure out what was and wasn't checked previously compared to what is and isn't checked upon postback in order to issue raise the events appropriately.
Let me know what you think. I'll post back here when I've got a more developed solution to propose to handle the TreeNodeCheckChanged problem. Again, thanks for the Page v. Parent fix in RaiseAdaptedEvent. Regards,
Groovybits.com
Russ Helfand
Contributor
3304 Points
744 Posts
Re: TreeView adapter problem
Sep 28, 2006 08:45 PM|LINK
... regarding the TreeNodeCheckedChanged event... Brian (and others who are running into this) it's very important that you review these notes, http://forums.asp.net/thread/1393604.aspx.
You MUST use the implementation pattern suggested in those notes. That is, if you are using the adapted TreeView you should be setting OnAdaptedTreeNodeCheckChanged in your <asp:TreeView>. Do not try to use the normal OnTreeNodeCheckChanged attribute.
Brian, were you aware of that? I know that chunk of information is buried at the moment. It will be made much more prominent in kit's real documentation in the next rev. Sorry if you ran afoul of it.
Groovybits.com
brian.brown
Member
25 Points
5 Posts
Re: TreeView adapter problem
Oct 06, 2006 08:16 PM|LINK
Right.. However removing the traditional OnTreeNodeCheckChanged attribute didn't keep the event from firing repeatedly for every checked node on every postback. I was originally posting about 3 problems until I realized that you were NOT supposed to have the OnAdapted attributes AND the traditional attributes definied.
Russ Helfand
Contributor
3304 Points
744 Posts
Re: TreeView adapter problem
Oct 06, 2006 09:08 PM|LINK
Actually, I think I was wrong with my last comment. Even if you have both OnTreeNodeCheckChanged and OnAdaptedTreeNodeCheckChanged (i.e., you have both the OnAdapted--- and the On--- version of the event handler) I don't think you should see them called in a duplicate fashion. Only one or the other should be being called.
I have been working on the TreeView adapter (for the next rev) a tremendous amount lately and have looked for this duplicate event invokation in the debugger, etc. I don't see it with my files.
Is there any way for you to create a very simple and complete test recipe that I can use to try to dup the problem here?
Groovybits.com
brian.brown
Member
25 Points
5 Posts
Re: TreeView adapter problem
Oct 08, 2006 07:39 PM|LINK
It is very easy to reproduce the problem with the CheckChanged event firing for ever cheked node on every postback. Just add a button to the WalkThru/CheckboxTreeView.aspx provided in the adapter downloads. Check a couple of the nodes and click the button. You will see the checkchanged event fire for each node that is checked. The checked state is remembered after the postback. Click the button again and the checkchanged event will fire again for each checked node even though their checked state was not changed.
Russ Helfand
Contributor
3304 Points
744 Posts
Re: TreeView adapter problem
Oct 08, 2006 10:45 PM|LINK
Just got back from the veggie garden and started digging into this... I have good news on several fronts.
First, and most immediately, I was able to duplicate the problem using Brian's latest recipe. The safest and most immediate fix for you is (happily) quite easy. Go to this posting, http://forums.asp.net/1/1397908/ShowThread.aspx. Locate my posting 09-12-2006, 5:33 PM. Cut-n-paste the code I posted there to create a version of the TreeViewAdapter.cs file in your site's App_Code\Adapters. (If you are using VB you may need to do a little conversion work. There are some nice online converters but you still need to do some hand tweaking afterwards. If you are using VB and are really stuck, let me know and I'll try to help.)
Note that there are other ideas discussed on http://forums.asp.net/1/1397908/ShowThread.aspx that some of you might want to explore but getting them integrated isn't as easy as the simple cut-n-paste recipe I just offered. Still, there are some great ideas there from others in the community.
OK, the other piece of good news is that all of these fixes will be included in the next rev of the kit so what you're struggling with now won't last forever. I apologize, though, for the immediate inconvenience. I'm working on other improvements to the TreeView adapter (like maintaining the true and complete expand/collapse state between postbacks) so your patience will be rewarded.
If the fix at http://forums.asp.net/1/1397908/ShowThread.aspx does not solve your problem (i.e., if you continue to see events being fired inappropriately and too often) let me know. My testing locally showed that applying the fix in http://forums.asp.net/1/1397908/ShowThread.aspx made this problem (which I could repro prior to applying the fix) go away. If your results vary from that... let me know.
Best regards,
Groovybits.com
ahsteele
Member
100 Points
112 Posts
Re: TreeView adapter problem
Jul 10, 2007 08:43 PM|LINK
Russ I am having this exact problem. In trying to fix it I attempted using your rewritten TreeViewAadapter from 09-12-2006, 5:33 PM to no avail. I believe that I am using the most recent rev of the adapters but, more than likely I am missing something very simple here. Any help would be greatly appreciated.
This can be beneficial to other community members reading the thread.