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

TemplateSourceDirectory

6 Answers 153 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Jay
Top achievements
Rank 1
Jay asked on 08 Feb 2008, 12:27 AM
Having trouble with the NavigateURL path resolution.... I'm using prometheus RadMenu Trial version: Version=2007.3.1328.35

I've built a menu with NavigateURL parameters to aspx pages within my root web project. The menu is housed inside a user control which is loaded inside my master page. The menu items are built dynamically from a datatable. Basically, only certain pages can be run by any given user based on their profile. So I fill a datatable with all the allowed "Menu Items". The Text value and NavigateURL value are bound at runtime.

The problem: Since RadMenu is derived from System.Web.UI.Control it implements the TemplateSourceDirectory property automatically when a NavigateURL property is set. Again this is at runtime not design time. Since the menu is inside a user control the relative path begins at the user control solution folder (e.g. /UserControls). As a result when the menu items are bound they are given the relative path of /UserControls then appended to it the NavigateURL. 

I need some help in overriding the TemplateSourceDirectory so all the relative paths point to the root. (e.g.
/ )?

Right now the menu items have a relative path of (
http://localhost:3534/UserControls/*.aspx)
I want them to have a relative path of
(http://localhost:3534/*.aspx)

Final note: Any solution must be done at runtime so the menu is dynamic based on the users profiile. HELP!!!! By the way - We have a PO in the works to purchase the full suite of Telerik for our dev team (5 licenses). Your immediate help will assist me in the go no go descision for the purchase.

Jay Ashbaugh

6 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 08 Feb 2008, 07:31 AM
Hi Jay,

I am not sure if this is possible at all. Could you implement the same with a regular HyperLink control or the built-in ASP.NET Menu? If yes we could help you migrate the code to RadMenu.

Looking forward to your reply,
Albert
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Jay
Top achievements
Rank 1
answered on 08 Feb 2008, 09:22 PM
Thanks for the quick reply - you blew away the 72hr response SLA on the trial version. It is much appreciated!

I have never overriden the TemplateSourceDirectory but since it's virtual I'm sure you can. The issue is related to how RadMenu performs a Response.Redirect() during a postback event. I would assume the dev team made a "line-in-the-sand" descision and said... rather than having the user see exceptions because the relative path is wrong - it's better to inherit and pre-pend the TemplateSourceDirectory to any MenuItem's NavigateURL.

Here is the workaround we found to enable you to direct page flow to the root directory. However, we do want to suggest that TELERIK consider a change in the RadMenu codebase to make it easier to use. Specifically, do not use the inherited TemplateSourceDirectory property but rather create a public property on the control for RootPath. Then TELERIK can pre-pend the realtive path as I have done below. The trick is for TELERIK define the public property in the assembly so we "lazycoder" types can populate it at design time (it's called a SET attribute) :-)

Solutions:
1. Modified the NavigateURL string and pre-pend "/" before the page name.
(http://localhost:3435/*.aspx)
The code:
NewItem.Value = "/" + MenuDTO.AppsDTO.Rows[x].ItemArray[1].ToString();

2. Follow -  http://www.telerik.com/community/forums/thread/b311D-ggdgk.aspx

Codebehind:

private void LoadMenu()

{

BE_AppsDTO MenuDTO = new BE_AppsDTO();

MenuDTO = BLManager.GetMenuItems(MenuDTO);

RadMenuItem RMI_Parent = new RadMenuItem("", "../Default.aspx");

RMI_Parent.HoveredImageUrl =

"../Images/MasterPage/Nav/ButtonHover.png";

RMI_Parent.ExpandedImageUrl =

"../Images/MasterPage/Nav/ButtonHover.png";

RMI_Parent.EnableTheming =

false;

RMI_Parent.ExpandMode =

MenuItemExpandMode.ClientSide;

RMI_Parent.Visible=

true;

RMI_Parent.Width =

Unit.Pixel(76);

RMI_Parent.Height =

Unit.Pixel(53);

RMI_Parent.BorderWidth =

Unit.Pixel(0);

RMI_Parent.CssClass =

"menu";

RMI_Parent.GroupSettings.ExpandDirection =

ExpandDirection.Auto;

RMI_Parent.GroupSettings.Flow =

ItemFlow.Vertical;

for (int x = 0; x < MenuDTO.AppsDTO.Rows.Count; x++)

{

RadMenuItem NewItem = new RadMenuItem();

NewItem.Text = MenuDTO.AppsDTO.Rows[x].ItemArray[0].ToString();

NewItem.Value =

"/" + MenuDTO.AppsDTO.Rows[x].ItemArray[1].ToString();

RMI_Parent.Items.Add(NewItem);

}

this.RadMenu.Items.Add(RMI_Parent);

}

protected void RadMenu_ItemClick(object sender, RadMenuEventArgs e)

{

Session[

"ApplicationName"] = e.Item.Text.ToString();

Response.Redirect(e.Item.Value.ToString());
}

}


ASPX Code:

<
telerik:RadMenu

ID="RadMenu"

Runat="server"

Flow="Horizontal"

EnableEmbeddedSkins="false"

Visible="true"

ClickToOpen="false"

Skin="Inox"

style="top: 0px; left: 0px; height: 53px; width: 70px" EnableOverlay="True"

OnItemClick="RadMenu_ItemClick" PersistLoadOnDemandItems="true">

<DefaultGroupSettings ExpandDirection="Auto" Flow="Vertical" />

<CollapseAnimation Duration="0" Type="None" />

<ExpandAnimation Type="None" Duration="0" />

</telerik:RadMenu>

0
Atanas Korchev
Telerik team
answered on 11 Feb 2008, 07:35 AM
Hi Jay,

RadMenu is using the following code to render the NavigateUrl property:

string url = ResolveClientUrl(NavigateUrl);

That url is then rendered as the "href" attribute of a hyperlink which represents the menu item.
I am not sure if ResolveClientUrl relies on TemplateSourceDirectory internally. Response.Redirect is not used anywhere in our code.

I hope this helps,
Atanas Korchev,
the Telerik dev team

Instantly find answers to your questions at the new Telerik Support Center
0
Jay
Top achievements
Rank 1
answered on 11 Feb 2008, 04:54 PM
Atanas,

Thanks again for the rapid response to my thread. I agree that the ResolveClientURL(<string>) is being used to return the relative path.
It does use the TemplateSourceDirectory property as RadMenu is derived from System.Web.UI.Control namespace and the control class uses it to resolve relative paths when no absolute path is provided.

Please refer to Telerik's own posting @ http://www.telerik.com/community/forums/thread/b311D-ggdgk.aspx
Joe has suggested users who dynamically bind the paths use
Response.Redirect() on the MenuItem click event. Obviously, he is suggesting Response.Redirect() to get around the implmentation of ResolveClientUrl(). So, if the suggestion is valid that means the RadMenu is capable of multiple implmentations and as such should contain a public property on the control so I can resolve to the directory of choice.

According to MS the following is suggested:
"To set a property with a path such as "~/path", resolve the path by calling the ResolveUrl with an argument such as "~/path" before assigning it to the property."
Found @ http://msdn2.microsoft.com/en-us/library/system.web.ui.control.resolveurl(ide).aspx

This means the RadMenu should be using ResolverUrl() rather than ResolveClientUrl(). Please shoot me the patched version when able.

public class RadMenu:Control
{
   private string _RootPath;    
   public string RootPath
   {
      get
      { return _RootPath; }
      set
      { _RootPath= value; }
   }
    private string _NavigateUrl; 
    public string NavigateUrl
   {
      get
      { return _NavigateUrl; }
      set
      { _NavigateUrl= value; }
   }

   protected override void Render(HtmlTextWriter output)
   {           
      RadMenu newRadMenu = new RadMenu();
      // Resolve Url.
if (this.RootPath == null || this.RootPath == "")
{
newRadMenu .NavigateURL = ResolveUrl(this.NavigateUrl);
}
else
{
newRadMenu .NavigateURL = ResolveUrl(this.RootPath+this.NavigateUrl);
 }
newRadMenu.RenderControl(output); } }
0
Atanas Korchev
Telerik team
answered on 11 Feb 2008, 05:04 PM
Hello Jay,

Unfortunately we don't plan to release such a version of RadMenu. We maintain our position that ResolveClientUrl should be used instead of ResolveUrl. Actually the same approach is used in the built-in ASP.NET HyperLink control - you can check the System.Web.UI.WebControls.HyperLink.AddAttributesToRender method using the Reflector tool.
I guess you can inherit from the RadMenu class and during the OnPreRender event traverse all items and resolve their NaivageUrl property in the way you want.

I hope this helps,
Atanas Korchev,
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Jay
Top achievements
Rank 1
answered on 11 Feb 2008, 10:39 PM
Ok, can't fault me for trying.....Thanks.
Best of luck to all those bound by this limitation.

Jay
Tags
Menu
Asked by
Jay
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Jay
Top achievements
Rank 1
Share this question
or