Treeview - open node in new window

M

Mel

I have a treeview control that contains a bunch of pdf filenames. It
would like the files to open in a new window. Can anyone assist me in
doing that? The code I currently have is below:

Protected Sub tvDocs_SelectedNodeChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles tvDocs.SelectedNodeChanged
Dim FilNam As String
FilNam = Mid(tvDocs.SelectedNode.Parent.ValuePath,
InStr(tvDocs.SelectedNode.Parent.ValuePath, "Docs\") + Len("Docs\")) &
"\" & tvDocs.SelectedValue
If InStr(UCase(tvDocs.SelectedValue), ".PDF") > 0 Then
Response.Redirect("~\1-New-Portal-Tree\" & FilNam)
End Sub


- Mel
(Visual Studio 2005, Asp.net 2.0, Visual Basic)
 
G

Guest

Hi Mel,
do you really need to process node selection on server? TreeNode has
NavigateUrl and Target properties properties. I assume you are binding
TreeView to same data source. You can implement TreeNodeDataBound handler and
set these properties for those nodes. Something like this

protected void myTreeView_NodeDataBound(Object sender, TreeNodeEventArgs e)
{
// Implement some method to check if your node contains pdf document
if(IsPDF(e.Node.Value))
{
// build your url to pdf document
e.Node.NavigateUrl = BuildMyPath(e.Node.Parent.Value, e.Node.Value);
e.Target = "_blank";
}
}

Regards,
Ladislav
 
M

Mel

Hi Mel,
do you really need to process node selection on server? TreeNode has
NavigateUrl and Target properties properties. I assume you are binding
TreeView to same data source. You can implement TreeNodeDataBound handler and
set these properties for those nodes. Something like this

protected void myTreeView_NodeDataBound(Object sender, TreeNodeEventArgs e)
{
// Implement some method to check if your node contains pdf document
if(IsPDF(e.Node.Value))
{
// build your url to pdf document
e.Node.NavigateUrl = BuildMyPath(e.Node.Parent.Value, e.Node.Value);
e.Target = "_blank";
}
}

Regards,
Ladislav

When the user clicks on a particular .pdf filename I want to open it
for them. Even though I have the target = "_blank" in the treeview
properties the file opens in the same browser window; I suspect
because I am using Redirect and maybe it's not capable of opening a
new window. I was just wondering if there was another way to open the
file where it would open in a new window. If anyone could provide a
detailed example I would really appreciate it.
 
M

Mel

Hi Mel,
do you really need to process node selection on server? TreeNode has
NavigateUrl and Target properties properties. I assume you are binding
TreeView to same data source. You can implement TreeNodeDataBound handler and
set these properties for those nodes. Something like this

protected void myTreeView_NodeDataBound(Object sender, TreeNodeEventArgs e)
{
// Implement some method to check if your node contains pdf document
if(IsPDF(e.Node.Value))
{
// build your url to pdf document
e.Node.NavigateUrl = BuildMyPath(e.Node.Parent.Value, e.Node.Value);
e.Target = "_blank";
}
}

Regards,
Ladislav

Thank you very much, I fixed it. I set the Navigate Url to the path
and it worked. I totally didn't realize that property even
existed ;) My original code was setting the path upon the
SelectedNodeChanged event. This way is much better. I removed all of
the code from the SelectedNodeChanged and now just set the NavigateUrl
when I fill the tree.

Many thanks,
Mel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top