ASP.NET Treeview selectedNodeStyle 
April 14th, 2006, 04:15 PM
| | | |
Hi,
I use the selectednodestyle with a white background so the user can see
which item was chosen in the treeview navigation.
The nodes have a navigateURL with a target to another frame.
Navigating works with no postback and the style follow the selected node.
When a new child is added to a node there is a button to refresh the node.
This is done by a postback. After this postback the selected node stays
keeps the selected style.
I think it is a bug.
Could I have done something wrong?
Any information is welcome.
Koen | 
April 14th, 2006, 07:35 PM
| | | | re: ASP.NET Treeview selectedNodeStyle
Hi,
There is no bug, you missed one line after adding the new node. when you
insert the new node then you make that your selectednode's selected property
is false. Sample code is below:
TreeView1.SelectedNode.Selected = false;
Have a nice work,
Aytaç ÖZAY
Software Engineer
<cyriel1920@nospam.nospam> wrote in message
news:02C37FFC-53B0-47A9-A9AF-C1F9951E551B@microsoft.com...[color=blue]
> Hi,
>
> I use the selectednodestyle with a white background so the user can see
> which item was chosen in the treeview navigation.
> The nodes have a navigateURL with a target to another frame.
> Navigating works with no postback and the style follow the selected node.
> When a new child is added to a node there is a button to refresh the node.
> This is done by a postback. After this postback the selected node stays
> keeps the selected style.
>
> I think it is a bug.
> Could I have done something wrong?
> Any information is welcome.
>
> Koen[/color] | 
April 17th, 2006, 05:15 AM
| | | | re: ASP.NET Treeview selectedNodeStyle
Hi Koen,
As Aytacozay, this is because the TreeView will always keep the selected
Node's info, so after you add new nodes and refresh the TreeView, have you
also unselected the original selected Node? If not, you need to mark it as
unselected as aytacozay mentioned.
Regards,
Steven Cheng
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights. | 
April 18th, 2006, 04:05 PM
| | | | re: ASP.NET Treeview selectedNodeStyle
Hi,
Thanks for the feedback.
I see the proposed solution as a workaround.
The tree is used as navigation in my project.
The user navigated to a certain item. The main frame is on a page related to
the item. If the user does a refresh on the nagivation, the main frame is on
the same page and it is desirable the tree shows the original selected node
as selected.
However when the user selects a new node the original node stays selected.
A second problem i noticed:
The selected style works well when clicking on the text of the node.
When the user clicks on the image the navigation works but the selected
style stays on the image. It stays on even when chosing a new item.
I know a solution: don't use images
I am convinced if the somebody from the ASP.NET team has a another look at
the code he/she can do improvements.
Koen
"Steven Cheng[MSFT]" wrote:
[color=blue]
> Hi Koen,
>
> As Aytacozay, this is because the TreeView will always keep the selected
> Node's info, so after you add new nodes and refresh the TreeView, have you
> also unselected the original selected Node? If not, you need to mark it as
> unselected as aytacozay mentioned.
>
> Regards,
>
> Steven Cheng
> Microsoft Online Community Support
>
>
> ==================================================
>
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
>
> ==================================================
>
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
>
>
>[/color] | 
April 19th, 2006, 07:15 AM
| | | | re: ASP.NET Treeview selectedNodeStyle
Thanks for your response Koen,
Yes, as for the ImageUrl for SelectedNodeStyle, it is an existing known
issue of the TreeView control, the dev team has recorded this for fixing in
future version. also, based on my test, when we use NavigationUrl for
TreeNode to act as hyperlink, the "SelectedNodeChanged" event won't get
fired for the TreeView which is also a problem. Currently what I have
tried is creating a cutsom Treeview class derived from the existing
Treeview, and I put some additional property to store Navigation Url, thus,
I can make all the Node as normal TreeViewNode(not hyperlink node) but use
my customTreeNode class, and in the Treeview's selectedNodechanged event, I
programmatically set Node's Url (reset original selectedNode's url) and
register client-script to do the navigation work. e.g:
Here is my custom Treeview and TreeNode's code:
===============================
namespace ControlLibrary
{
public class CustomTreeView : TreeView
{
protected override TreeNode CreateNode()
{
return new CustomTreeNode();
}
}
public class CustomTreeNode : TreeNode
{
private string _navurl;
public string NavUrl
{
get
{
return _navurl;
}
set
{
_navurl = value;
}
}
}
}
===========================
=========aspx page============
<cc1:CustomTreeView ID="TreeView1" runat="server" Target="main"
SelectedNodeStyle-ImageUrl="~/Images/nor.GIF"
OnSelectedNodeChanged="TreeView1_SelectedNodeChang ed"
[color=blue]
>[/color]
<SelectedNodeStyle ImageUrl="~/Images/nor.GIF"
BackColor="Lime" />
<Nodes>
<cc1:CustomTreeNode Text="New Node1" Target="main"
Value="New Node1" NavUrl="http://www.asp.net">
<cc1:CustomTreeNode Text="New Node11" Target="main"
Value="New Node11" NavUrl="http://www.asp.net/?id=1"></cc1:CustomTreeNode>
<cc1:CustomTreeNode Text="New Node12" Target="main"
Value="New Node12" NavUrl="http://www.asp.net/?id=2"></cc1:CustomTreeNode>
</cc1:CustomTreeNode>
<cc1:CustomTreeNode Text="New Node2" Target="main"
Value="New Node2">
<cc1:CustomTreeNode Text="New Node21" Target="main"
Value="New Node21"></cc1:CustomTreeNode>
<cc1:CustomTreeNode Text="New Node22" Target="main"
Value="New Node22"></cc1:CustomTreeNode>
</cc1:CustomTreeNode>
<cc1:CustomTreeNode Text="New Node3" Value="New Node3">
<cc1:CustomTreeNode Text="New Node31" Value="New
Node31"></cc1:CustomTreeNode>
<cc1:CustomTreeNode Text="New Node32" Value="New
Node32"></cc1:CustomTreeNode>
</cc1:CustomTreeNode>
</Nodes>
<NodeStyle ImageUrl="~/Images/sel.GIF" />
</cc1:CustomTreeView>
===========code behind========================
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
string oldvaluepath = TreeView1.Attributes["oldnodepath"];
CustomTreeNode oldNode = TreeView1.FindNode(oldvaluepath) as
CustomTreeNode;
if (oldNode != null) { oldNode.ImageUrl =
TreeView1.NodeStyle.ImageUrl; }
TreeView1.SelectedNode.ImageUrl =
TreeView1.SelectedNodeStyle.ImageUrl;
TreeView1.Attributes["oldnodepath"] =
TreeView1.SelectedNode.ValuePath;
string script = @"<script language='javascript'>
window.parent.frames['{0}'].location.href = '{1}';
</script>";
CustomTreeNode node = TreeView1.SelectedNode as CustomTreeNode;
Page.ClientScript.RegisterStartupScript(this.GetTy pe(),
"TreeView_Select_Script",
string.Format(script, node.Target, node.NavUrl ));
}
==============================
Yes, this is quite abit complex and not very elegant, however, we're
limited to the existing interfaces.
also, sorry for the inconvenience this brings you.
Regards,
Steven Cheng
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights. | 
April 19th, 2006, 08:35 AM
| | | | re: ASP.NET Treeview selectedNodeStyle
Steven,
Thanks for your effort.
Your solution result in a postback to do the navigation.
I 'll stick with the navigateURL and wait for the fix.
Koen
"Steven Cheng[MSFT]" wrote:
[color=blue]
> Thanks for your response Koen,
>
> Yes, as for the ImageUrl for SelectedNodeStyle, it is an existing known
> issue of the TreeView control, the dev team has recorded this for fixing in
> future version. also, based on my test, when we use NavigationUrl for
> TreeNode to act as hyperlink, the "SelectedNodeChanged" event won't get
> fired for the TreeView which is also a problem. Currently what I have
> tried is creating a cutsom Treeview class derived from the existing
> Treeview, and I put some additional property to store Navigation Url, thus,
> I can make all the Node as normal TreeViewNode(not hyperlink node) but use
> my customTreeNode class, and in the Treeview's selectedNodechanged event, I
> programmatically set Node's Url (reset original selectedNode's url) and
> register client-script to do the navigation work. e.g:
>
>
> Here is my custom Treeview and TreeNode's code:
>
> ===============================
> namespace ControlLibrary
> {
> public class CustomTreeView : TreeView
> {
> protected override TreeNode CreateNode()
> {
> return new CustomTreeNode();
> }
>
>
> }
>
>
> public class CustomTreeNode : TreeNode
> {
> private string _navurl;
>
>
> public string NavUrl
> {
> get
> {
> return _navurl;
> }
> set
> {
> _navurl = value;
> }
> }
>
> }
>
> }
> ===========================
>
> =========aspx page============
> <cc1:CustomTreeView ID="TreeView1" runat="server" Target="main"
> SelectedNodeStyle-ImageUrl="~/Images/nor.GIF"
> OnSelectedNodeChanged="TreeView1_SelectedNodeChang ed"
>[color=green]
> >[/color]
> <SelectedNodeStyle ImageUrl="~/Images/nor.GIF"
> BackColor="Lime" />
>
> <Nodes>
> <cc1:CustomTreeNode Text="New Node1" Target="main"
> Value="New Node1" NavUrl="http://www.asp.net">
> <cc1:CustomTreeNode Text="New Node11" Target="main"
> Value="New Node11" NavUrl="http://www.asp.net/?id=1"></cc1:CustomTreeNode>
> <cc1:CustomTreeNode Text="New Node12" Target="main"
> Value="New Node12" NavUrl="http://www.asp.net/?id=2"></cc1:CustomTreeNode>
> </cc1:CustomTreeNode>
> <cc1:CustomTreeNode Text="New Node2" Target="main"
> Value="New Node2">
> <cc1:CustomTreeNode Text="New Node21" Target="main"
> Value="New Node21"></cc1:CustomTreeNode>
> <cc1:CustomTreeNode Text="New Node22" Target="main"
> Value="New Node22"></cc1:CustomTreeNode>
> </cc1:CustomTreeNode>
> <cc1:CustomTreeNode Text="New Node3" Value="New Node3">
> <cc1:CustomTreeNode Text="New Node31" Value="New
> Node31"></cc1:CustomTreeNode>
> <cc1:CustomTreeNode Text="New Node32" Value="New
> Node32"></cc1:CustomTreeNode>
> </cc1:CustomTreeNode>
> </Nodes>
> <NodeStyle ImageUrl="~/Images/sel.GIF" />
> </cc1:CustomTreeView>
>
> ===========code behind========================
>
> protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
> {
>
>
> string oldvaluepath = TreeView1.Attributes["oldnodepath"];
>
> CustomTreeNode oldNode = TreeView1.FindNode(oldvaluepath) as
> CustomTreeNode;
>
> if (oldNode != null) { oldNode.ImageUrl =
> TreeView1.NodeStyle.ImageUrl; }
>
> TreeView1.SelectedNode.ImageUrl =
> TreeView1.SelectedNodeStyle.ImageUrl;
> TreeView1.Attributes["oldnodepath"] =
> TreeView1.SelectedNode.ValuePath;
>
>
> string script = @"<script language='javascript'>
>
> window.parent.frames['{0}'].location.href = '{1}';
> </script>";
>
>
> CustomTreeNode node = TreeView1.SelectedNode as CustomTreeNode;
>
> Page.ClientScript.RegisterStartupScript(this.GetTy pe(),
> "TreeView_Select_Script",
> string.Format(script, node.Target, node.NavUrl ));
> }
> ==============================
>
> Yes, this is quite abit complex and not very elegant, however, we're
> limited to the existing interfaces.
>
> also, sorry for the inconvenience this brings you.
>
> Regards,
>
> Steven Cheng
> Microsoft Online Community Support
>
>
> ==================================================
>
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
>
> ==================================================
>
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
>
>
>
>
>
>
>
>
>
>
>[/color] | 
April 19th, 2006, 11:55 AM
| | | | re: ASP.NET Treeview selectedNodeStyle
Thanks for the followup.
I agree and understand your consideration. Anyway, please feel free to post
here if there is anything else we can help.
Regards,
Steven Cheng
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights. |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,689 network members.
|