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

Open in new tab when NavigateUrl is blank

3 Answers 482 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Marco Piumi
Top achievements
Rank 2
Marco Piumi asked on 17 Apr 2015, 04:17 PM

In order to handle the event Item Click on the menu, I had to reset the NavigateUrl property in each Item.

But by doing so, I do not work any more chance, to the context menu, to open the menu page in a new tab, as it always opens the current page.

Is there a solution for this problem?

It would not be useful in a new version of the menu, a property that forces the event ItemClick even in the presence of a value in the property NavigateUrl?

Thanks.

3 Answers, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 21 Apr 2015, 02:11 PM
Hello,

Could you please explain in detail your scenario?
  1. Do you use RadMenu or RadContextMenu?
  2. What should happen when a user clicks on a RadMenuItem? Do you want the browser to open a new tab and load the page you specify in the NavigateUrl property or you want to cancel the navigation?

Regards,
Ivan Danchev
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Marco Piumi
Top achievements
Rank 2
answered on 21 Apr 2015, 08:47 PM

I am using the control Radmenu.

When I load the menu from code, leave blank the NavigateUrl property, and load an attribute containing the url :

item.Attributes["NavigateUrl"] = "~/" + dr["PaginaWeb"].ToString();

When you click the menu item opens the page read in attribute:

protected void mnuWebBoleroNetMobile_ItemClick(object sender, Telerik.Web.UI.RadMenuEventArgs e)
{
    if (e.Item.Value.Length != 0) Utility.ScriveLogProgramma(new Guid(e.Item.Value), this.Request,  Convert.ToInt32(Session["CodiceUtente"])); // Write Log

    Response.Redirect(e.Item.Attributes["NavigateUrl"].ToString());

}

If I click the right mouse button on the menu item, before, with the property NavigateUrl charge, if I pointed to open a new tab, the corresponding page was opened in a new tab.

Now with the property NavigateUrl empty, to force the event Item Click, this is no longer possible.

How is it possible, in this condition, again have the opportunity to open in a new tab, a menu item?

Maybe, if there was a new property, which enables the event ItemClick even if that property NavigateUrl is full, the problem would be solved.

Do you have another idea to solve the problem?
Thank you.

0
Ivan Danchev
Telerik team
answered on 24 Apr 2015, 12:26 PM
Hello,

Thank you for the explanation.

Since navigating to a page when a user clicks on a RadMenuItem prevents the ItemClick event from firing, if you want to execute some custom logic in this events handler (like logging for instance) you can set the NavigateUrl property in it and then open a new browser window, as demonstrated in the code below:
protected void mnuWebBoleroNetMobile_ItemClick(object sender, RadMenuEventArgs e)
{
    e.Item.NavigateUrl = "http://www.telerik.com";
    string url = e.Item.NavigateUrl;
 
    StringBuilder sb = new StringBuilder();
    sb.Append("<script type = 'text/javascript'>");
    sb.Append("window.open('");
    sb.Append(url);
    sb.Append("');");
    sb.Append("</script>");
 
    ClientScript.RegisterStartupScript(this.GetType(), "script", sb.ToString());
}

Regards,
Ivan Danchev
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
Menu
Asked by
Marco Piumi
Top achievements
Rank 2
Answers by
Ivan Danchev
Telerik team
Marco Piumi
Top achievements
Rank 2
Share this question
or