That throws an error.
Object reference not set to an instance of an object.
Main Topics
Browse All TopicsHi, I'm trying to find out, from my master page code behind, if a page includes a certain content placeholder.
If the page includes the content placeholder I need to add a class in my master page and show a panel.
I've tried looping through Page.Controls but it doesn't seem to be giving me what i want.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
b'coz Page does not contain content place holder. When you apply master page to content page it adds
<asp:Content ID="content1" ContentPlaceHolderID="focu
</asp:Content
so you use like this may be
foreach (System.Web.UI.Control ctrl in Page.Controls)
{
Content c = ctrl as Content;
if( c != null)
{
if (c.ContentPlaceHolderID == "focusAreaPlaceHolder")
{
controlsinfo.Text = "found it";
return;
}
}
}
@jinal,
that last block of code doesn't print out anything in my label. not sure if it's getting into the if statement or not, didn't debug.
@all,
I started thinking of it a bit differently...i realize the contentplaceholder was always in the controls collection on the master page, so I wondered if maybe I could just figure out if it was empty or not. I found this article which helped:
http://programcsharp.com/b
That returns true or false depending on whether the page itself has the <asp:content> tag on it for the particular placeholder.
I realize now my original question wording was a bit misleading. I wasn't looking for the placeholder itself, I was looking for the <asp:content> tag that was associated with a certain placeholder.
Business Accounts
Answer for Membership
by: ki_kiPosted on 2009-07-15 at 10:38:39ID: 24861879
is there a Page.Findcontrol("focusAre aPlaceHold er") ??