views:

1166

answers:

3

I have to find the IDs of all the contentPlaceHolders in a MasterPage.

A: 

Iterate through all Controls and recursively through their subcontrols and check the type and if they are contentplaceholders you have the ID.

Gambrinus
An example would be gr8..As I am using a nested Master Page . I have written a function which takes MasterPage as Parameter and loops throus all the controls. but for some unknown reason its not able to find the ContentPlaceHolder
Perhaps you should edit your question to include the code you have already written.
Cerebrus
+1  A: 

Just query the ContentPlaceHolders property which returns an IList containing all the CPH names in the given Master page.

VB code: (Sorry!)

'In the Master Page.
For Each cphID As String In Me.ContentPlaceHolders
  Debug.WriteLine(cphID)
Next
Cerebrus
The thing is I have to pass MasterPage as parameter to the function. I cant write a function in Master Page
+1  A: 

try:

for (string cphID in ((MasterPageType)this.MasterPage).ContentPlaceHolders)
{
   Debug.WriteLine(cphID);
}

In the code behind of your page, and replace MasterPageType with the type of your master page

Adam Naylor