Force ImageUrl to Absolute

6 posts, 0 answers
  1. JonB
    JonB avatar
    7 posts
    Member since:
    Mar 2008

    Posted 26 Jun 2008 Link to this post

    I have created a simple menu of images using the ImageUrl property.

    The menu exists on a site with custom url translation.  i.e. http://tempuri.org/viewProduct/123/1.aspx = http://tempuri.org/viewProduct.aspx?productId=123

    The images in the menu are written using relative paths ( ../folder/img.jpg ) which causes the image not to show up when using a custom url.

    How can I change the way the menu writes the urls to foce absolute urls to address this issue?

    Thanks in advance,
    Jon B.
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 27 Jun 2008 Link to this post

    Hi JonB,

    You can use the following lines of code to make the URL absolute:

                foreach (RadMenuItem item in RadMenu1.GetAllItems())
                {
                    item.ImageUrl = item.ResolveUrl(item.ImageUrl);
                }

    You need to executed once your menu is populated.

    Regards,
    Albert
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. JonB
    JonB avatar
    7 posts
    Member since:
    Mar 2008

    Posted 27 Jun 2008 Link to this post

    Thank you for your response.

    This addresses one issue that the images are using full relative paths rather than using parent paths, but I would prefer to control the urls so that they are absolute rather than relative.

    I have implemented your example with the additions below.   Please let me know of other ways to change the rendering of the urls.

    protected void RadMenu1_PreRender( object sender, EventArgs e )
    {
        foreach ( RadMenuItem itm in RadMenu1.GetAllItems() )
        {
            itm.ImageUrl = itm.ResolveUrl( itm.ImageUrl );
            itm.ImageOverUrl = itm.ResolveUrl( itm.ImageOverUrl );
            itm.ImageClickedUrl = itm.ResolveUrl( itm.ImageClickedUrl );

            itm.NavigateUrl = itm.ResolveUrl( itm.NavigateUrl );
        }
    }

  4. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 27 Jun 2008 Link to this post

    Hi JonB,

    As far as I know there is no other way to change the rendering of the urls apart from the one demonstrated. How do you resolve this problem with other controls - hyperlinks for example? Perhaps you can use the same approach with RadMenu.

    Regards,
    Albert
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. JonB
    JonB avatar
    7 posts
    Member since:
    Mar 2008

    Posted 27 Jun 2008 Link to this post

    I am able to manipulate the way all <asp:Image/> tags render the image urls is by a System.Web.UI.Adapters.ControlAdapter.

    This allows me to ensure that all images have absolute urls.

    This updated all images on the web site, except for the images used in the RadMenu.

    I use the same concept for <asp:Hyperlink/>.
  6. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 30 Jun 2008 Link to this post

    Hello JonB,

    RadMenu does not use the Image control to render its images - hence the control adapter does not override the rendering. The same goes with the link rendered by it. Perhaps you could use the implementation from your control adapter to "translate" the URL and set the ImageUrl and NavigateUrl properties of the menu items.

    Regards,
    Albert
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top