Findcontrol problem

Discussion in 'ASP .Net' started by kpg, Jul 16, 2007.

  1. kpg

    kpg Guest

    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
     
    kpg, Jul 16, 2007
    #1
    1. Advertising

  2. kpg

    kpg Guest

    "Patrice" <http://www.chez.com/scribe/> wrote in
    news::

    > 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
     
    kpg, Jul 16, 2007
    #2
    1. Advertising

  3. "kpg" <> wrote in message
    news:Xns996F8077B386Eipostthereforeiam@207.46.248.16...

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


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Jul 16, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jaime

    FindControl problem

    Jaime, May 20, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    675
    Jaime
    May 20, 2005
  2. =?Utf-8?B?dHBhcmtzNjk=?=

    ItemCreated FindControl problem c#

    =?Utf-8?B?dHBhcmtzNjk=?=, Jun 16, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    6,520
    =?Utf-8?B?QkVMSVVT?=
    Jun 16, 2005
  3. Arjen

    Findcontrol problem

    Arjen, Oct 17, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    2,044
    Scott Allen
    Oct 18, 2005
  4. ThunderMusic
    Replies:
    2
    Views:
    421
    ThunderMusic
    Oct 9, 2006
  5. Terry

    problem with FindControl

    Terry, Feb 15, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    591
    Terry
    Feb 15, 2007
Loading...

Share This Page