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

BarChart - Add Click Event to Series Item Label

2 Answers 140 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 10 May 2013, 02:59 PM
I am attempting to add a click event to my SeriesItems Labels. The handle seems to get bound to the label but it isn't hit when the label is clicked in the browser. Also the mouse doesn't change from default to pointer which seems to be typical behavior for Telerik controls with a click event attached. 

protected void RC_OnItemDataBound(object sender, ChartItemDataBoundEventArgs e)
        {
            e.SeriesItem.Label.ActiveRegion.Click += new RegionClickEventHandler(RCLbl_OnClick);
       }


Where am I going wrong here?

2 Answers, 1 is accepted

Sort by
0
Petar Kirov
Telerik team
answered on 15 May 2013, 03:01 PM
Hi Alex,

I can confirm that this is a bug in the control. You should be able receive click events from the series item label, given your code.
To work around this you can use the href attribute of the active region to trigger a PostBack manually. Then you can override the RaisePostBackEvent method of your page and in it use the information for the currently clicked series item.
void Chart_ItemDataBound(object sender, ChartItemDataBoundEventArgs e)
{
    int itemIndex = e.SeriesItem.Index;
    int seriesIndex = e.ChartSeries.Index;
    string chartID = this.chart.ID;
 
    e.SeriesItem.Label.ActiveRegion.Attributes = string.Format(
        "href=javascript:__doPostBack(\"{2}\",\"true,{0},{1}\")",
        seriesIndex, itemIndex,
        chartID);
}
 
protected override void RaisePostBackEvent(System.Web.UI.IPostBackEventHandler sourceControl, string eventArgument)
{
    if (sourceControl == this.chart)
    {
        var stringTokens = eventArgument.Split(',');
        int seriesIndex = int.Parse(stringTokens[1]);
        int itemIndex = int.Parse(stringTokens[2]);
 
        var seriesItem = this.chart.Series[seriesIndex].Items[itemIndex];
        //use seriesItem accordingly...
    }
}

I hope this helps.
 
Regards,
Petar Kirov
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.
0
Alex
Top achievements
Rank 1
answered on 15 May 2013, 05:27 PM
This solved my issue. I ended using the following for Label OnClick:

      e.SeriesItem.Label.ActiveRegion.Url = "URL";
Tags
Chart (Obsolete)
Asked by
Alex
Top achievements
Rank 1
Answers by
Petar Kirov
Telerik team
Alex
Top achievements
Rank 1
Share this question
or