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

Force ImageUrl to Absolute

5 Answers 113 Views
Menu
This is a migrated thread and some comments may be shown as answers.
JonB
Top achievements
Rank 1
JonB asked on 26 Jun 2008, 05:23 PM
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.

5 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 27 Jun 2008, 06:21 AM
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
0
JonB
Top achievements
Rank 1
answered on 27 Jun 2008, 08:21 AM
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 );
    }
}

0
Atanas Korchev
Telerik team
answered on 27 Jun 2008, 08:59 AM
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
0
JonB
Top achievements
Rank 1
answered on 27 Jun 2008, 03:36 PM
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/>.
0
Atanas Korchev
Telerik team
answered on 30 Jun 2008, 08:45 AM
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
Tags
Menu
Asked by
JonB
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
JonB
Top achievements
Rank 1
Share this question
or