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

Setting the alt attribute on the node image

1 Answer 208 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Jon Shipman
Top achievements
Rank 1
Jon Shipman asked on 15 Aug 2012, 10:44 PM
I set the ImageURL property of the TreeView Nodes during the NodeDataBound event.  I want to set the text for the "alt" attribute of the image.  If I set the ToolTip property of the Node, it adds the ToolTip text to the alt property of the Node image, but it also adds a "title" property with the same text to the entire text of the node.  This is unwanted.

So, the question is: How can I set the image alt text on a node, during binding in code, without adding the same text as the title attribute for the text?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 20 Aug 2012, 04:16 PM
Hello Jon,

Thank you for contacting Telerik Support team,

One really easy and convenient approach to achieve this behavior is to use javascript and jQuery. You could use this piece of code:

<script type="text/javascript">
    var $ = $telerik.$;  
 
    $(document).ready(function () {
     $('.rtImg').each(function () {
  var $img = $(this);
  var filename = $img.attr('src')
  $img.attr('alt', filename.substring(0, filename.lastIndexOf('.')));
                                });
                        });
</script>

Here you can find some detailed information about client-side approach.

If you have any further questions, don't hesitate do contact us again.

Regards,
Boyan Dimitrov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
TreeView
Asked by
Jon Shipman
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Share this question
or