Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

ASP.net Sitemap with link to open in new window

  • 11-11-2008 02:55PM
    #1
    Registered Users, Registered Users 2 Posts: 2,793 ✭✭✭


    Hi,

    I'm very surprised to see that the ASP.net Sitemap control does not allow for the target="_blank" attribute.

    I have an external link and need to open it on a new page. Anyone overcome this problem before?

    Thanks in advance,
    John


Comments

  • Registered Users, Registered Users 2 Posts: 2,894 ✭✭✭TinCool


    I have used the below code in one of my apps to open a link in a new window with a bit of client side javascript from a button click event.
        Protected Sub btnBrandedNumbers_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBrandedNumbers.Click
            Dim RedirectURL As String = "[URL]http://yourwebsite/Default.aspx[/URL]"
            Dim RedirectNewWindow As String = "<SCRIPT LANGUAGE=""JavaScript"">window.open('" + RedirectURL + "','_blank');</SCRIPT>"
            ClientScript.RegisterClientScriptBlock(Me.GetType(), "ClientScript", RedirectNewWindow)
        End Sub
    


  • Registered Users, Registered Users 2 Posts: 610 ✭✭✭nialo


    This has worked for me... Bind sitemap to a Menu control and use the following.
    protected void MenuBar_MenuItemDataBound(object sender, MenuEventArgs e)
    {
    e.Item.Target = "_blank";
    }
    


  • Registered Users, Registered Users 2 Posts: 21,278 ✭✭✭✭Eoin


    Can you set the link target in the header tag for the site map?


  • Registered Users, Registered Users 2 Posts: 2,793 ✭✭✭John_Mc


    TinCool wrote: »
    I have used the below code in one of my apps to open a link in a new window with a bit of client side javascript from a button click event.
        Protected Sub btnBrandedNumbers_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBrandedNumbers.Click
            Dim RedirectURL As String = "[URL]http://yourwebsite/Default.aspx[/URL]"
            Dim RedirectNewWindow As String = "<SCRIPT LANGUAGE=""JavaScript"">window.open('" + RedirectURL + "','_blank');</SCRIPT>"
            ClientScript.RegisterClientScriptBlock(Me.GetType(), "ClientScript", RedirectNewWindow)
        End Sub
    

    Thanks for the reply but would like to avoid injecting JS.
    nialo wrote: »
    This has worked for me... Bind sitemap to a Menu control and use the following.
    protected void MenuBar_MenuItemDataBound(object sender, MenuEventArgs e)
    {
    e.Item.Target = "_blank";
    }
    

    Thanks, will try this out now!
    eoin_s wrote: »
    Can you set the link target in the header tag for the site map?

    I don't believe so, at least my good friend Google didnt come back with anything like that. And the MSDN didnt mention anything either


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    In the sitemap.xml

    <siteMapNode url="Home.aspx" title="Home" target="_blank">

    For example will launch in a new window

    http://weblogs.asp.net/dannychen/archive/2005/03/28/396099.aspx


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,793 ✭✭✭John_Mc


    Ginger wrote: »
    In the sitemap.xml

    <siteMapNode url="Home.aspx" title="Home" target="_blank">

    For example will launch in a new window

    http://weblogs.asp.net/dannychen/archive/2005/03/28/396099.aspx

    Thanks! As I already said, it's a bit crazy that they didnt provide for this type of functionality out of the box :confused:


Advertisement