BarChart - Add Click Event to Series Item Label

Thread is closed for posting
3 posts, 0 answers
  1. Alex
    Alex avatar
    8 posts
    Member since:
    Apr 2013

    Posted 10 May 2013 Link to this post

    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. Petar Kirov
    Admin
    Petar Kirov avatar
    425 posts

    Posted 15 May 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Alex
    Alex avatar
    8 posts
    Member since:
    Apr 2013

    Posted 15 May 2013 Link to this post

    This solved my issue. I ended using the following for Label OnClick:

          e.SeriesItem.Label.ActiveRegion.Url = "URL";
Back to Top