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

How to add Javascript Event as Attribute to RadRating in Grid

1 Answer 85 Views
Rating
This is a migrated thread and some comments may be shown as answers.
Kellie
Top achievements
Rank 1
Kellie asked on 27 Jul 2010, 05:45 PM
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;
    }
}

1 Answer, 1 is accepted

Sort by
0
Tsvetie
Telerik team
answered on 29 Jul 2010, 03:27 PM
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
Tags
Rating
Asked by
Kellie
Top achievements
Rank 1
Answers by
Tsvetie
Telerik team
Share this question
or