Findcontrol problem

  • Thread starter Thread starter kpg
  • Start date Start date
K

kpg

InASP.NET 2.0 I have a checkbox named CB1

<asp:CheckBox ID="CB1" runat="server" />

In the Page_Load event:

dim cb as checkbox
cb = ctype(findcontrol("CB1"), checkbox)

but cb = nothing

Am I going crazy? This should work, right?

tia
kpg
 
Not necessarily (FindControl search in the current naming container).
As you didn't mentioned anything in your code, it search in the page
container and it's likely your control is declared actually in a inner
container (else you coud directly use the variable name of course).

Try MyContainer.FindControl instead...

Yes, this is a big gotcha for those of us new to master pages.


First, use page.master.findcontrol to get a ref to the content
placeholder, then use the findcontrol of the content placeholder.


http://msdn2.microsoft.com/en-us/library/xxwa0ff0.aspx

Thanks for the reply
kpg
 
Yes, this is a big gotcha for those of us new to master pages.

One of the most common misconceptions about MasterPages is that they are
somehow the ASP.NET 2 equivalent of framesets - nothing could be further
from the truth.

In fact, a MasterPage is nothing more than a particular kind of
UserControl...

Once you've realised that the MasterPage doesn't control the content page -
it's completely the other way round - everything becomes clear... :-)
 
Back
Top