Last post Jun 08, 2010 12:04 PM by s0uth
Aug 22, 2006 05:30 PM|Eric Fettman|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 22, 2006 11:19 PM|lostlander|LINK
Use Page.Master.FindControl instead.
Aug 23, 2006 06:53 AM|Eric Fettman|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 02:16 PM|Eric Fettman|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 10:53 AMemail@example.com|LINK
Brilliant Man, you saved me a lot of time with show me how to use master.findcontrol stuff. brilliant.....................
Feb 18, 2010 10:05 AM|athornicroft|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 12:04 PM|s0uth|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"