Open in new tab when NavigateUrl is blank

4 posts, 0 answers
  1. Marco Piumi
    Marco Piumi avatar
    29 posts
    Member since:
    Apr 2005

    Posted 17 Apr 2015 Link to this post

    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.

  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    832 posts

    Posted 21 Apr 2015 Link to this post

    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.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Marco Piumi
    Marco Piumi avatar
    29 posts
    Member since:
    Apr 2005

    Posted 21 Apr 2015 in reply to Ivan Danchev Link to this post

    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.

  5. Ivan Danchev
    Admin
    Ivan Danchev avatar
    832 posts

    Posted 24 Apr 2015 Link to this post

    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.

     
Back to Top