Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 08, 2010 04:04 PM by s0uth
Aug 22, 2006 09:30 PM|LINK
Hi, Folks --
I'm using the following C# static method to populate some DropDownLists from XML files:
select = (
select.DataSource = ds;
I'm calling the method from a code-behind page as follows:
This is the problem: the method returns a NullReferenceException if I call it from a page that has a MasterPage because FindControl is not returning anything. This is a problem ONLY if the page is associated with a MasterPage.
Any thoughts appreciated.
Aug 23, 2006 03:19 AM|LINK
Use Page.Master.FindControl instead.
Aug 23, 2006 10:53 AM|LINK
Thanks for your response.
The controls that I'm populating with XML are not in the MasterPage, so I don't think that this is going to work.
Any other ideas?
Aug 23, 2006 06:16 PM|LINK
I found a solution:
Thanks, Rick Strahl.
All I had to change was:
and also the signature of the method so it accepts all Control objects and not just Page objects:
Oct 17, 2007 02:53 PM|LINK
Brilliant Man, you saved me a lot of time with show me how to use master.findcontrol stuff. brilliant.....................
Feb 18, 2010 02:05 PM|LINK
Hi i have also had a problem with findcontrol with master pages, i found
this thread useful
lblData.Text = ((TextBox)PreviousPage.Master.FindControl("ContentPlaceHolderBody").FindControl("txtData")).Text;
Jun 08, 2010 04:04 PM|LINK
Dim mpContentPlaceHolder As ContentPlaceHolder
Dim mpTextBox As TextBox
mpContentPlaceHolder = _
If Not mpContentPlaceHolder Is Nothing Then
mpTextBox = CType(mpContentPlaceHolder.FindControl("TextBox1"), TextBox)
If Not mpTextBox Is Nothing Then
mpTextBox.Text = "TextBox found!"
if you want find control in page with masterpages,first you have find control "contentplaceholder"