Rating Items ImageURL

2 posts, 0 answers
  1. eric
    eric avatar
    4 posts
    Member since:
    Apr 2011

    Posted 12 Apr 2012 Link to this post

    All the standard ASP.net controls that have a ImageURL property accept relative urls (ex. ~/img/image.gif)

    When I place a relative URL into a Rad Rating Item, it doesn't resolve the URL, it simply embeds this as a literal value to the page's CSS.

    <telerik:RadRatingItem CssClass="ratingItem" Value="1" ImageUrl="~/img/ratings/rating_1_normal.png" ToolTip="Very Easy" SelectedImageUrl="~/img/ratings/rating_1_selected.png" HoveredImageUrl="~/img/ratings/rating_1_hover.png" />

    I can adjust the URL's accordingly by removing the ~/ and change it to an absolute path, however when published to a server sometimes the path is a little different. This results in the images not displaying because the CSS is pointing to the wrong place.  Is this by design?

    I used this code to resolve the URLs so that I could use relative paths in the image URL properties:
    If String.IsNullOrEmpty(item.ImageUrl) = False Then
                  If item.ImageUrl.StartsWith("~/") Then
                      item.ImageUrl = ResolveUrl(item.ImageUrl)
                  End If
              End If
              If String.IsNullOrEmpty(item.SelectedImageUrl) = False Then
                  If item.SelectedImageUrl.StartsWith("~/") Then
                      item.SelectedImageUrl = ResolveUrl(item.SelectedImageUrl)
                  End If
              End If
              If String.IsNullOrEmpty(item.HoveredImageUrl) = False Then
                  If item.HoveredImageUrl.StartsWith("~/") Then
                      item.HoveredImageUrl = ResolveUrl(item.HoveredImageUrl)
                  End If
              End If
              If String.IsNullOrEmpty(item.HoveredSelectedImageUrl) = False Then
                  If item.HoveredSelectedImageUrl.StartsWith("~/") Then
                      item.HoveredSelectedImageUrl = ResolveUrl(item.HoveredSelectedImageUrl)
                  End If
              End If

    Is there ever going to be an implementation of allowing relative paths in the image URL fields?
  2. Niko
    Niko avatar
    404 posts

    Posted 13 Apr 2012 Link to this post

    Hello Eric,

     The RadRating items are working by default in this mode. Still you can use the ResolveUrl or ResolveClientUrl and assign the resolved paths to the ImageUrl property of each item on the server side. An example follows:
    theRating.Items[0].ImageUrl = ResolveClientUrl("~/content/testImages/logo.png");

    Hope this helps.

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