Referring to content controls

  • Thread starter Thread starter Mike P
  • Start date Start date
M

Mike P

I have several <asp:Content> controls on my page as I am using a master
page. But I cannot refer to these content controls in my code on this
page and I need to make one of them visible and invisible at different
times. How do I do this?
 
Enable trace in the content page, load it, locate your control in the traced
output, observe the control tree hierarchy and reuse the values of the
hierarchy as arguments passed to the FindControl method.

//example 1 (typ)
Label errorLabel =
Master.FindControl("CenterPanelContent").FindControl("MoreGoofyShit").FindControl("EvenMoreGoofyShit").FindControl("AreYouGettingTheMessageHowFUBARASP.NET_ReallyIs).FindControl("FinallyMyLabelIsFound")
as Label;

Yes, it really is that ugly and yes, ASP.NET really has been left this FUBAR
even though they are on 3.5 and be advised there are other bugs that will
require using whole dame hierarchy as a single FindControl argument...

// example 1 (can be compelled with the buggy 2.0 controls)
Label errorLabel =
Master.FindControl(CenterPanelContent$MoreGoofyShit$EvenMoreGoofyShit$AreYouGettingTheMessageHowFUBAR_ASP.NET_ReallyIs$FinallyMyLabelIsFound")
as Label;
 
You would not do this using the Content control, you would do it using the
ContentPlaceHolder in the Master Page. To do this from the codebehind of
your content page, you will need to do it in the PreInit event. Hopefully
this helps.
 
Back
Top