How to Get RotatorItem's Attributes at client-side

4 posts, 1 answers
  1. Thomas
    Thomas avatar
    8 posts
    Member since:
    Dec 2010

    Posted 29 Dec 2010 Link to this post

    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.
  2. Answer
    Fiko
    Admin
    Fiko avatar
    1406 posts

    Posted 04 Jan 2011 Link to this post

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

    Posted 04 Jan 2011 Link to this post

    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.
  5. Rumen
    Admin
    Rumen avatar
    12851 posts

    Posted 06 Jan 2011 Link to this post

    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.
Back to Top