Click here to Skip to main content
15,879,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to set Target attribute value of dynamically created treenode to iframe in web application using vb.net code ?
Posted
Updated 26-Dec-11 0:39am
v2

1 solution

Hi Rupali,

You can use javascript to achieve this

<asp:treeview id="TreeView1" runat="server" xmlns:asp="#unknown">
       <nodes>
           <asp:treenode navigateurl="javascript:nav();" text="Hello"></asp:treenode>
       </nodes>
   </asp:treeview>


Javascript function

<script language="text/javascript">
  function nav() {
            document.getElementById('iframe1').src = "getdata.aspx";                 
        }
    </script></script>


You can even set NavigateUrl property from the code behind in .vb file

Hope this will help :)

Thanks
Vinod
 
Share this answer
 
Comments
Rupali sawant 27-Dec-11 1:34am    
Hi Vinod,
Thanks for ur reply

Actually I am ignoring to use Javascript, bcoz Mozilla firefox not supporting to javascript so I trying by using code behind page.

I am creating treeview dynamically and each treenode have the link for different pages.In my page Treeview is on left side & iframe is on right.When click on Treenode link I want to dispaly related page in that iframe.I tried by using "Target" & "NavigateUrl" properties.But linked page open in new window instead of iframe.

My Coding .....

<asp:Content ID="Content1" ContentPlaceHolderID="CPHLeftNav" runat="server">
<asp:Panel ID="pnl_leftNav" runat="server" Visible="false" Style="font: 11px/16px Arial,sans-serif;"
Heigh="100%">
<asp:TreeView ID="TreeView2" runat="server" Style="margin-left: 0px; text-align: left;
margin-left: 0px; padding-left: 0px" Font-Bold="True" ExpandDepth="0" ForeColor="Indigo"
Height="100%" Width="100%" OnSelectedNodeChanged="TreeView2_SelectedNodeChanged"
PopulateNodesFromClient="true" ShowExpandCollapse="true" ImageSet="Arrows"
Target="ifrm1" >
<ParentNodeStyle Font-Bold="true" ForeColor="Firebrick" />
<hovernodestyle font-underline="True" forecolor="#5555DD">
<SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px"
VerticalPadding="0px" />
<nodes>
<asp:TreeNode Text="SomeText" ToolTip="BillEntryForm" Value="SomeText" Target="iframe">


<rootnodestyle forecolor="Firebrick">
<nodestyle forecolor="Black" horizontalpadding="5px" nodespacing="0px" verticalpadding="0px">




<asp:Content ID="Content2" ContentPlaceHolderID="CPHRightContent" runat="server">
<iframe id="ifrm1" runat="server" width="10%" height="10%"></iframe>




Protected Sub TreeView2_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView2.SelectedNodeChanged
ifrm1.Attributes.Add("src", TreeView2.SelectedNode.Value.ToString())
End Sub


'''On Loging button click i called the procedure "PopulateRootLevel()"


Private Sub PopulateRootLevel()
''Retriving Data from database
PopulateNodes(dt, TreeView2.Nodes)
End Sub

Private Sub PopulateNodes(ByVal dt As DataTable, _ByVal nodes As TreeNodeCollection)
For Each dr As DataRow In dt.Rows
Dim tn As New TreeNode()
tn.Value = dr("id").ToString()
tn.Text = dr("NText").ToString()
tn.ToolTip = dr("NTooltip").ToString()
tn.Target = ifrm1.ClientID
tn.NavigateUrl = dr("NNavigateUrl").ToString()

'''Some code
nodes.Add(tn)
''''
tn.PopulateOnDemand = (CInt(dr("childnodecount")) > 0)
Next
End Sub

Private Sub PopulateSubLevel(ByVal parentid As Integer, ByVal parentNode As TreeNode)
''' Code for Retrieving Data From database
PopulateNodes(dt, parentNode.ChildNodes)
End Sub

Protected Sub TreeView2_TreeNodePopulate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView2.TreeNodePopulate
PopulateSubLevel(CInt(e.Node.Value), e.Node)
End Sub
Vinod Satapara 27-Dec-11 2:01am    
Hi Rupali,

my code works fine in all browsers. I have tested it with the firefox. Also it is not possible without the javascript.

I am modifying your code

<asp:Content ID="Content1" ContentPlaceHolderID="CPHLeftNav" runat="server">
<asp:Panel ID="pnl_leftNav" runat="server" Visible="false" Style="font: 11px/16px Arial,sans-serif;"
Heigh="100%">
<asp:TreeView ID="TreeView2" runat="server" Style="margin-left: 0px; text-align: left;
margin-left: 0px; padding-left: 0px" Font-Bold="True" ExpandDepth="0" ForeColor="Indigo"
Height="100%" Width="100%" OnSelectedNodeChanged="TreeView2_SelectedNodeChanged"
PopulateNodesFromClient="true" ShowExpandCollapse="true" ImageSet="Arrows"
Target="ifrm1" >
<ParentNodeStyle Font-Bold="true" ForeColor="Firebrick" />

<SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px"
VerticalPadding="0px" />

<asp:TreeNode Text="SomeText" ToolTip="BillEntryForm" Value="SomeText" Target="iframe">








<asp:Content ID="Content2" ContentPlaceHolderID="CPHRightContent" runat="server">
<iframe id="ifrm1" runat="server" width="10%" height="10%"></iframe>

<script language="javascript">
function nav(url)
{
document.getElementById('<%=ifrm1.ClientID%>').src = url;
}
</script>


Protected Sub TreeView2_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView2.SelectedNodeChanged
ifrm1.Attributes.Add("src", TreeView2.SelectedNode.Value.ToString())
End Sub

-------------------------------------------

Private Sub PopulateRootLevel()
''Retriving Data from database
PopulateNodes(dt, TreeView2.Nodes)
End Sub

Private Sub PopulateNodes(ByVal dt As DataTable, _ByVal nodes As TreeNodeCollection)
For Each dr As DataRow In dt.Rows
Dim tn As New TreeNode()
tn.Value = dr("id").ToString()
tn.Text = dr("NText").ToString()
tn.ToolTip = dr("NTooltip").ToString()
tn.NavigateUrl = "javascript:nav('"+dr("NNavigateUrl").ToString()+"')";

'''Some code
nodes.Add(tn)
''''
tn.PopulateOnDemand = (CInt(dr("childnodecount")) > 0)
Next
End Sub

Private Sub PopulateSubLevel(ByVal parentid As Integer, ByVal parentNode As TreeNode)
''' Code for Retrieving Data From database
PopulateNodes(dt, parentNode.ChildNodes)
End Sub

Protected Sub TreeView2_TreeNodePopulate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView2.TreeNodePopulate
PopulateSubLevel(CInt(e.Node.Value), e.Node)
End Sub

Rupali sawant 29-Dec-11 2:28am    
Thanks sooooooo much vinodji
problem solved.Your code is Very helpful to me.
God bless you....
U know i spend many days on this problem......
Thanks a lot ...

Thanks,
Rupali
Vinod Satapara 29-Dec-11 4:53am    
You are welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900