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

How to Get RotatorItem's Attributes at client-side

3 Answers 43 Views
Rotator
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 29 Dec 2010, 09:04 AM
Dear Sir/Madam

I am facing the following problem: 
I set some attributes on a rotator's item at server-side using
protected void ItemRotator_OnItemDataBound(object sender, RadRotatorEventArgs e) {
    DataRowView drv = (e.Item.DataItem as DataRowView);       
    e.Item.Attributes.Add("dbID"     , drv["ID"].ToString()      );
    e.Item.Attributes.Add("dbCaption", drv["Caption"].ToString() );       
}

But i cannot get them at client side. I am using the following code at client-side:
function GetAttributeValue(anObject, strProperty) {
    if (anObject) {
        var attributes = anObject.get_attributes();
        if (attributes) {
            return attributes.getAttribute(strProperty);
        } else alert("Object.get_attributes() == null");
    } else alert("Invalid Object");
}
 
var SelectedItemGUID
var SelectedItemTitle
  function rotator_OnItemShow(sender, args) {        
    var targetIndex = args.get_item().get_index();
    SelectedItemGUID = GetAttributeValue(args.get_item() , "dbID");
    SelectedItemTitle = GetAttributeValue(args.get_item(), "dbCaption");           
  }

Function GetAttributeValue works fine with other telerik objects (ie TreeNodes) and i Know (for debug) that the rotator_OnItemShow is call when it should be.
Internet Explorer 8 gives me this error report
Message: Object doesn't support this property or method

Thank you for your time,
Thomas Sarmis.

3 Answers, 1 is accepted

Sort by
0
Accepted
Fiko
Telerik team
answered on 04 Jan 2011, 10:57 AM
Hi Thomas,

You need to implement your code using this code in order to retrieve the custom attribute:
function GetAttributeValue(anObject, strProperty)
{
    if (anObject)
    {
        var attributes = $telerik.$('[TestAttribute]:first', anObject.get_element()).attr("TestAttribute");
        alert(attributes);
        if (attributes)
        {
            return attributes;
        }
        else
            alert("Object.get_attributes() == null");
    }
    else alert("Invalid Object");
}

For your convenience I have attached a demo to this thread.

Kind regards,
Fiko
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Thomas
Top achievements
Rank 1
answered on 04 Jan 2011, 11:05 AM
Fiko,
Thank you or your answer - I believe this will solve my problems.

May I ask why this is needed for the rotator (for the rest controls- ie Treeview) my code worked fine...

Thank you.
0
Rumen
Telerik team
answered on 06 Jan 2011, 11:09 AM
Hi Thomas,

The args.get_item() method does not return the element you expect. It returns a parent element of the element containing the specified attribute.That is why you should use the code provided by Fiko to get a reference to the expected element and obtain its attribute.

Kind regards,
Rumen
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Rotator
Asked by
Thomas
Top achievements
Rank 1
Answers by
Fiko
Telerik team
Thomas
Top achievements
Rank 1
Rumen
Telerik team
Share this question
or