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

node.set_imageUrl(null) bug:

7 Answers 208 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
N
Top achievements
Rank 1
N asked on 14 Jan 2008, 09:12 AM

I tried the following client-side code without success. If the node has no image, you can successfully set  the node to point to an image but you cannot remove the image after that. In other words, the following does not change anything, the current image remains assigned:

node.set_imageUrl(null);
node.set_expandedImageUrl(null);

Setting the value to an empty string (instead of null) does not work either. Any suggestions?

Thanks,
Nuri

7 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 14 Jan 2008, 09:24 AM
Hi Nuri,

This currently is not supported. Maybe you can remove the image by removing it from the DOM tree:

var img = node.get_imageElement();
img.parentNode.removeChild(img).

I hope this helps,
Albert
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
N
Top achievements
Rank 1
answered on 14 Jan 2008, 08:47 PM
Thanks Albert,

I need to re-enable the image on the client-side though, so removing the image object seems a bit extreme. For the benefit of others I ended up hiding the image like this:

var img = node.get_imageElement();
img.style.display="none";

and later showing it again like this:

var img = node.get_imageElement();
img.style.display="block";

Regards,
Nuri
0
Andy
Top achievements
Rank 1
answered on 12 Jan 2009, 02:46 AM
I had to use:

 

dependentNode.get_imageElement().style.display = "inline"

 

to show the image, otherwise the layout got messed up when repeatedly hiding / showing. On IE7, other browsers might not need this.

 

0
Sky
Top achievements
Rank 1
answered on 16 Jan 2011, 09:27 PM
Removing image or hiding image will not work with trackChanges(). Anytime postback occurs, the image will be shown again. Any other solution?

Thanks.
0
Kamen Bundev
Telerik team
answered on 19 Jan 2011, 09:47 PM
Hello Sky,

Currently it is not possible to track the RadTreeView ImageURL removal using this hack, it is client-only. We will investigate for a possible solution for this issue, but I can't give you a specific time frame for that.

All the best,
Kamen Bundev
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Roberto
Top achievements
Rank 1
answered on 13 Jul 2018, 05:24 PM

I'm trying to remove an image from a node.

Is this still the only way?

0
Peter Milchev
Telerik team
answered on 17 Jul 2018, 11:18 AM
Hello Roberto,

The client changes now can be accessed in the code behind as explained in https://docs.telerik.com/devtools/aspnet-ajax/controls/treeview/client-side-programming/accessing-client-changes-on-the-server-side. Here is an example that works as below:



<script>   
    function OnClientClicked(sender, args) {               
        var treeview = $find("<%= RadTreeView1.ClientID %>");
        treeview.trackChanges();
        var node = treeview.findNodeByText("MyNode");
        node.set_imageUrl("")
        treeview.commitChanges();               
    }
</script>

<telerik:RadButton runat="server" ID="RadButton2" autopostback="true" Text="Postback"></telerik:RadButton>
<telerik:RadButton runat="server" ID="RadButton1" autopostback="false" OnClientClicked="OnClientClicked" Text="Remove Image"></telerik:RadButton>
<telerik:RadTreeView runat="server" ID="RadTreeView1" OnLoad="RadTreeView1_Load">
    <Nodes>
        <telerik:RadTreeNode Text="MyNode" ImageUrl="https://placeimg.com/32/32/any"></telerik:RadTreeNode>
    </Nodes>
</telerik:RadTreeView>

protected void RadTreeView1_Load(object sender, EventArgs e)
{
 
    var treeview = RadTreeView1;
    foreach (ClientOperation<RadTreeNode> operation in treeview.ClientChanges)
    {
        RadTreeNode node = operation.Item;
 
        switch (operation.Type)
        {
            case ClientOperationType.Insert:
                break;
            case ClientOperationType.Remove:
                break;
            case ClientOperationType.Update:
                UpdateClientOperation<RadTreeNode> update = operation as UpdateClientOperation<RadTreeNode>;
                if (update.PropertyName == "ImageUrl")
                {
                    treeview.FindNodeByText(update.Item.Text).ImageUrl = update.Item.ImageUrl;
                }
 
                break;
            case ClientOperationType.Clear:
                break;
        }
    }
}


Regards,
Peter Milchev
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
TreeView
Asked by
N
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
N
Top achievements
Rank 1
Andy
Top achievements
Rank 1
Sky
Top achievements
Rank 1
Kamen Bundev
Telerik team
Roberto
Top achievements
Rank 1
Peter Milchev
Telerik team
Share this question
or