Hi, Folks --
I'm using the following C# static method to populate some DropDownLists from XML files:
public
static void PopulateDD(Page page, List<string> dropDowns)
{
DataSet ds = new DataSet();
DropDownList select;
foreach (string dropDown in dropDowns)
{
select = (
DropDownList)page.FindControl("dd"+dropDown);
ds.ReadXml(page.Server.MapPath(
"~/xml/"+dropDown+".xml"));
select.DataSource = ds;
select.DataTextField =
"text";
select.DataValueField =
"text";
select.DataBind();
ds.Clear();
}
}
I'm calling the method from a code-behind page as follows:
List
<string> dropDowns = new List<string>();
dropDowns.Add(
"State");
dropDowns.Add(
"Country");
dropDowns.Add(
"Industry");
ControlUtils.PopulateDD(this.Page, dropDowns);
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.
TIA,
Eric