More in this section

Forums / Developing with Sitefinity / Adding OnClick handler to TaxonomyControl

Adding OnClick handler to TaxonomyControl

2 posts, 0 answered
  1. Dan
    Dan avatar
    8 posts
    30 Apr 2013
    11 Jun 2013
    Link to this post

    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?

  2. Pavel Benov
    Pavel Benov avatar
    341 posts
    14 Mar 2016
    14 Jun 2013
    Link to this post
    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.

    Pavel Benov
    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
2 posts, 0 answered