Click here to Skip to main content
14,692,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to add TreeView dynamically to Master Page from Child Page.
Please guide me.
If possible please tell me, how to access Master Page's container control from Child Page & add control to that container.

Any kind of help will be appreciated.
Thanks.
Posted

You don't add the tree to the master page from the child pages. You create content areas that the child pages can implement.
   
Just place the treeview control in the content placeholder in the content page which is the child page as you are naming it.
   
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

AGNMaster = CType(Page.Master, MasterPage)

Dim XMLdataSource1 = New XmlDataSource
Dim TreeView1 = New TreeView
Dim Content1 = New Content
Dim PlaceHoder1 = New PlaceHolder

PlaceHoder1.ID = "PlaceHolder1"
TreeView1.ID = "TreeView1"
XMLdataSource1.ID = "XMLdataSource1"
XMLdataSource1.DataFile = "~/XMLFile.xml"
TreeView1.DataSourceID = "XMLdataSource1"
'PlaceHolder1.ID = "PlaceHolder1"
Content1.ID = "Content1"


PlaceHolder1.Controls.Add(TreeView1)
PlaceHolder1.Controls.Add(XMLdataSource1)
Content1.Controls.Add(PlaceHolder1)



Dim PnlObject = New Panel


'PnlObject = Master.FindControl("ContentPlaceHolder1")
PnlObject = CType(Master.FindControl("Panel1"), Panel)
'PnlObject.Equals("")

'PnlObject.Controls.Add(AGNMaster.FindControl("Panel1"))

'If PnlObject IsNot Nothing Then
PnlObject.Controls.Add(Content1)
'End If
'AGNMaster.Controls.Add(PlaceHolder1)



End Sub
End Class
   
Comments
Not Active 17-Jul-11 11:10am
   
First, format the code snippet.
Second, this line, Master.FindControl("ContentPlaceHolder1") is absolutely unnecessary and a ridiculous way of doing this. The contentplaceholder should already on the child page.

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