LoadControl and CType error

Discussion in 'ASP .Net Building Controls' started by Justin Dutoit, Feb 23, 2006.

  1. Hey. I'm trying to dynamically add User Controls to my page. It appears to
    work sometimes, but more often I get the error:
    Unable to cast object of type 'ASP.SearchControl' to type
    'ASP.SearchControl'.

    Dim ctlNextSearch As Control = LoadControl("SearchCB.ascx")
    CType(ctlNextSearch, SearchControl).SearchString = SearchItems(Counter)
    MyPlaceHolder.Controls.Add(ctlNextSearch)

    In the User Control the directive is:
    <%@ Control ClassName="SearchControl" Language="VB" %>

    I would appreciate any help, thanks.

    Tks
    Justin Dutoit
     
    Justin Dutoit, Feb 23, 2006
    #1
    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. Justin Dutoit

    Help- LoadControl and Ctype error

    Justin Dutoit, Feb 23, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    735
    Sonu Kapoor [MVP]
    Feb 23, 2006
  2. AlecL

    Ctype error in Load control

    AlecL, Feb 1, 2007, in forum: ASP .Net
    Replies:
    4
    Views:
    414
  3. Durgesh Sharma
    Replies:
    5
    Views:
    900
    E. Robert Tisdale
    Dec 21, 2004
  4. Replies:
    3
    Views:
    182
  5. Nestor

    LoadControl and Multiple IDs in UserControls Error

    Nestor, Nov 10, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    196
    .net noobie
    Nov 12, 2005
Loading...

Share This Page