Findcontrol problem

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
 
K

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
 
M

Mark Rae [MVP]

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... :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top