Adding OnClick handler to TaxonomyControl

Posted by Community Admin on 04-Aug-2018 09:40

Adding OnClick handler to TaxonomyControl

All Replies

Posted by Community Admin on 11-Jun-2013 00:00

Hi

I have a custom control inherited from TaxonomyControl. What I want is to add an OnClick event handler when the user clicks on one of the categories on the page. How can I do this?

TIA
Dan

Posted by Community Admin on 14-Jun-2013 00:00

Hello Dan,

The Taxonomy control uses Hyperlink to display the categories and tags which does not provide Click event handler to manage through code behind. If you want to run a Javascript you can either modify the template and add the handler there (then register the template through the ViewMap), or you can override the TaxonomyControl and add it through code behind like so for example:

public class CustomTaxonomyControl : TaxonomyControl
    
        protected override void TaxaRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        
            base.TaxaRepeater_ItemDataBound(sender, e);
 
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            
                var link = e.Item.FindControl("link") as HyperLink;
                link.Attributes.Add("onClick", "alert('Hello')");
            
        
    

If you want to execute server side code I would suggest to take a look at this thread.

Regards,
Pavel Benov
Telerik
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed