Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FindControl - can't find dropdownlist

I have a dropdownlist:

<asp:DropDownList ID="ddlGoalKeeper" runat="server">
                </asp:DropDownList>

A nice little one. I have some code to find it:

DropDownList myControl1 = (DropDownList)Page.FindControl("ddlGoalKeeper");

Not.. it's just that my myControl1 doesn't get set... so when i later in my code try to set visible to true, it doesn't work.

Any ideas?

like image 966
Oedum Avatar asked Oct 31 '25 04:10

Oedum


1 Answers

One reason I have run in to for that not to work is if the control is when the site uses a master page.

You can use this idea to get a reference first to the master page and then get the right control from the content page:

 ContentPlaceHolder MainContent = Page.Master.FindControl("MainContent") as ContentPlaceHolder;
 DropDownList myControl1 = (DropDownList)MainContent.FindControl("ddlGoalKeeper");
like image 51
Jay Avatar answered Nov 01 '25 19:11

Jay