Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

ASP.net Sitemap with link to open in new window

Options
  • 11-11-2008 3:55pm
    #1
    Registered Users Posts: 2,791 ✭✭✭


    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 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 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 Posts: 21,257 ✭✭✭✭Eoin


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


  • Registered Users Posts: 2,791 ✭✭✭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 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 Posts: 2,791 ✭✭✭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