How to add Javascript Event as Attribute to RadRating in Grid

2 posts, 0 answers
  1. Kellie
    Kellie avatar
    29 posts
    Member since:
    Feb 2009

    Posted 27 Jul 2010 Link to this post

    Im having trouble adding a client side event as an attribute to the RadRating through the code behind. The RadRating is in a GridEditForm within a Grid so I'm having trouble "finding" controls when I try to do the javascript through the ASPX page.

    Below is an example of my attempt. As you see I am trying to add a simple alert to the onclientrated event. When tracing the code, it doesn't seem to add the attribute. If you have a different solution to help me find controls within the Radgrid Editforms, please let me know.

    Thanks Kellie

    protected void RadGridAssetExtrasCondition_ItemDataBound(object sender, GridItemEventArgs e)
    {
        switch (e.Item.OwnerTableView.Name)
        {
            case "AssetExtrasCondition":
                if (e.Item is GridCommandItem)
                {
                    Do some stuff here
                }
                if (e.Item is GridDataItem)
                {
                    Do some stuff here
                }
                if ((e.Item is GridEditFormItem || e.Item is GridEditFormInsertItem) && e.Item.IsInEditMode)
                {
                    var ctrlLabelConditionRatingDescription = (Label)e.Item.FindControl("LabelConditionRatingDescription");
                    var ctrlRadRatingCondition = (RadRating)e.Item.FindControl("RadRatingCondition");
      
      
                    // Creating the Rad Rating stars dynamically
                    foreach (var item in this.ConditionRatings.Items)
                    {
                        var ratingItem = new RadRatingItem
                                             {
                                                 Value = Convert.ToDecimal(item.Rating),
                                                 ToolTip = item.Rating.ToString()
                                             };
                        ctrlRadRatingCondition.Items.Add(ratingItem);
                    }
      
                    ctrlRadRatingCondition.Attributes.Add("onclientrated", "alert('hello');");
      
                    if (!e.Item.OwnerTableView.IsItemInserted)
                    {
                       Do some stuff here
                    }
                }
                break;
        }
    }
  2. Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 29 Jul 2010 Link to this post

    Hello Kellie,
    In order to attach a handler for the rated client-side event of RadRating, you should use the OnClientRated server-side property. For example:
    ctrlRadRatingCondition.OnClientRated = "OnClientRated";

    In the code fragment above, the OnClientRated string is the name of the client-side function that will be executed when the event fires:
    function OnClientRated(sender, args)
    {
        alert('hello');
    }

    Best wishes,
    Tsvetie
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top