Adding OnClick handler to TaxonomyControl
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
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')"
);