Find a control within a area

If you are using master pages, you may expect that you can find a control within an tag with the following

me.findcontrol("fckEditor")

But unfortunately that doesn’t work.
You need to make a reference to the place holder the control is in, then find the control within the place holder.
Another gotcha here is that you need to find this control based on the id it has on the master page not the id it has in the page in question.
e.g.
If the tags on the page are

<asp:Content ID="Content2" ContentPlaceHolderID="cphMain" Runat="Server">
</asp:Content>

You need to create a reference to the place holder with

Dim myContentPlaceHolder As ContentPlaceHolder
myContentPlaceHolder = CType(Master.FindControl("cphMain"), ContentPlaceHolder)

and not

Dim myContentPlaceHolder As ContentPlaceHolder
myContentPlaceHolder = CType(Master.FindControl("Content2"), ContentPlaceHolder)

Hope that saves someone some time!

This entry was posted by nerdboy on Tuesday, October 7th, 2008 at 2:52 pm and is filed under asp.net. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response below, or trackback from your own site.

Show/Hide Comments (0)

No Reader Comments (Be The First?)

Leave a Reply

(Required)
(Required)