Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Specify Target using SiteMap

Status
Not open for further replies.

robertfah

Programmer
Mar 20, 2006
380
US
I'm dynamically creating a SiteMap and I'd like to be able to open a URL in a new window (target='_blank') but I can't seem to find the place to do so. Does anyone know how this can be done instead of putting Javascript inside the URL to open a new window?

Here's part of my code to make the SiteMap:

public override SiteMapNode BuildSiteMap()
{
// Since the class is exposed to multiple pages,
// use locking to make sure that the site map is not rebuilt by more than one
// page at the same time.
lock (this)
{
// Start with a clean slate.
Clear();

// Get the results in a DataSet
DataSet ds = new DataSet();
ds = SiteData.UserInformation.Instance.GetMenuOptions();
DataTable dtSiteMap = ds.Tables["MenuOptions"];

// Get the root node.
DataRow rowRoot = dtSiteMap.Select("ParentID IS NULL")[0];
rootNode = new SiteMapNode(this,
rowRoot["URL"].ToString(), rowRoot["URL"].ToString(),
rowRoot["Title"].ToString(), rowRoot["Description"].ToString());
string rootID = rowRoot["MenuOptionID"].ToString();

// Fill down the hierarchy.
AddChildren(rootNode, rootID, dtSiteMap);
}
return rootNode;
}
 
Ok, I found a way. Simply use the MenuItemDataBound method to bind the target, like so:

//Apply the Target path to the Menu Item.
if (e.Item.Value == "Calendar")
e.Item.Target = "_blank";

In the case above, I've got a menu item in my DB with the title "Calendar" that I want to open in a new window. This works great as I don't have to store JS in the DB. I know it would be a mess if I had several links to open or if the links changed alot, but this is the only link on my menu (out of 25) that will open in a new window.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top