This is a migrated thread and some comments may be shown as answers.

[Solved] target="_blank" on TreeViewItem URL

3 Answers 80 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Corey
Top achievements
Rank 1
Corey asked on 02 Mar 2011, 10:47 PM
I am trying to get TreeViewItems that are loaded on demand to have their URL open in a new window/tab when they are clicked. I am using a JSON call to a method that builds an array of TreeViewItems and i am adding the target as a LinkHtmlAttribute, but it is not working and that property is not being returned n the JSON object.

View (Initial TreeView) - Incidentally the target="_blank" works for these parent TreeViewItems
<%= Html.Telerik().TreeView()
        .Name("TreeView")
        .BindTo(Model.Categories, (item, c) =>
            {
                item.Text = c.Name;
                item.Value = c.ID.ToString();
                item.LoadOnDemand = !c.IsProductCategory;
                item.Url = "/Maintenance/EditCategory/" + c.ID.ToString();
                item.Enabled = true;
                item.LinkHtmlAttributes.Add("target", "_blank");
                })
            .DataBinding(dataBinding => dataBinding
                   .Ajax().Select("TreeBranch", "Maintenance")
            )
%>

Controller
[ActionName("TreeBranch"), AcceptVerbs(HttpVerbs.Post)]
       public ActionResult TreeBranch(TreeViewItem node)
       {
           AdminCategoryService.CategoryServiceClient csc = new AdminCategoryService.CategoryServiceClient();
           ProductMaintenanceModel pmm = new ProductMaintenanceModel();
 
           int? id = !string.IsNullOrEmpty(node.Value) ? (int?)Convert.ToInt32(node.Value) : null;
           if (id != null)
           {
               pmm.Categories = csc.GetSubCategories(Convert.ToInt32(id));
               TreeViewItem[] nodes = new TreeViewItem[pmm.Categories.Length];
 
               for (int i = 0; i < pmm.Categories.Length; i++)
               {
                   nodes[i] = new TreeViewItem();
                   nodes[i].Text = pmm.Categories[i].Name;
                   nodes[i].Value = pmm.Categories[i].ID.ToString();
                   nodes[i].LoadOnDemand = !pmm.Categories[i].IsProductCategory;
                   nodes[i].Url = "/Maintenance/EditCategory/" + pmm.Categories[i].ID.ToString();
                   nodes[i].Enabled = true;
                   nodes[i].LinkHtmlAttributes.Add("target", "_blank");
               }
 
               return Json(nodes);
           }
 
           return null;
       }

Here is one of the TreeViewItems copied from Firebug to show that the LinkHtmlAttributes isn't included.
{"Items":[],"Value":"456","Expanded":false,"Checked":false,"Checkable":true,"LoadOnDemand":true,"Encoded":true,"ImageUrl":null,"SpriteCssClasses":null,"Text":"Shipping Supplies","Selected":false,"Enabled":true,"Url":"/Maintenance/EditCategory/456"}

Any help would be appreciated.

3 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 03 Mar 2011, 08:43 AM
Hello Corey,

 
LinkHtmlAttributes dictionary is not serialized to the client, because currently applying set attributes from it on client is not supported. I will forward this thread to our developers for further consideration. We will determine whether to implement this functionality depending on the users interest.

You can accomplish your task as wiring onSelect client event and in its handler to navigate to new window.

Regards,
Georgi Krustev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Alexey
Top achievements
Rank 1
answered on 20 Sep 2011, 04:26 AM
This is a must have feature. Its absence is very inconvenient as I use TreeView extensively in various scenarious.
Tags
TreeView
Asked by
Corey
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Alexey
Top achievements
Rank 1
Florian
Top achievements
Rank 1
Share this question
or