HowTo: Dynamically Add Custom Controls?

Discussion in 'ASP .Net Building Controls' started by David Freeman, Nov 3, 2004.

  1. Hi There!

    I'm having trouble dynamically adding custom controls. My custom controls
    does not use code-behind but only <script /> block for programming. So as a
    result, I don't need to compile my custom controls to dll for them to work.

    But I wonder, if I don't compile to dll, can I still dynamically add that
    custom control? If so how? Below is how I've tried (and failed).

    At top of the page...
    <%@ Register TagPrefix="MyControls" Src="DynamicTest.ascx"
    TagName="DynamicTest" %>


    In the <script /> block...

    Sub Page_Load(Sender As Object, e As EventArgs)

    Dim objNew as New DynamicTest '<< Raised Error: BC30002: Type
    'DynamicTest' is not defined

    Controls.Add(objNew)

    End Sub

    What I'm doing wrong here? I'm really hitting my head against the wall. Plz,
    anyone could help, I really appreciate it!

    David
     
    David Freeman, Nov 3, 2004
    #1
    1. Advertising

  2. sombody plz help!!

    David

    "David Freeman" <> wrote in message
    news:%...
    > Hi There!
    >
    > I'm having trouble dynamically adding custom controls. My custom controls
    > does not use code-behind but only <script /> block for programming. So as
    > a result, I don't need to compile my custom controls to dll for them to
    > work.
    >
    > But I wonder, if I don't compile to dll, can I still dynamically add that
    > custom control? If so how? Below is how I've tried (and failed).
    >
    > At top of the page...
    > <%@ Register TagPrefix="MyControls" Src="DynamicTest.ascx"
    > TagName="DynamicTest" %>
    >
    >
    > In the <script /> block...
    >
    > Sub Page_Load(Sender As Object, e As EventArgs)
    >
    > Dim objNew as New DynamicTest '<< Raised Error: BC30002: Type
    > 'DynamicTest' is not defined
    >
    > Controls.Add(objNew)
    >
    > End Sub
    >
    > What I'm doing wrong here? I'm really hitting my head against the wall.
    > Plz, anyone could help, I really appreciate it!
    >
    > David
    >
     
    David Freeman, Nov 3, 2004
    #2
    1. Advertising

  3. Ok. First of all you are not creating custom control but a user control.
    User control is NEVER a separate DLL but a part of the application DLL.

    User controls consist of ascx and a codebehind. If you just want to make an
    instance of the codebehind the codebehind doesn't know what is its ASCX
    file. Dynamic loading of USER controls should be run with LoadControl()
    method which you provide an ASCX file, which on the other hand has the
    information about the codebehind to correctly load the class from the DLL to
    handle it's content.

    --
    RobertK
    { Clever? No just smart. }

    "David Freeman" <> wrote in message
    news:#...
    > Hi There!
    >
    > I'm having trouble dynamically adding custom controls. My custom controls
    > does not use code-behind but only <script /> block for programming. So as

    a
    > result, I don't need to compile my custom controls to dll for them to

    work.
    >
    > But I wonder, if I don't compile to dll, can I still dynamically add that
    > custom control? If so how? Below is how I've tried (and failed).
    >
    > At top of the page...
    > <%@ Register TagPrefix="MyControls" Src="DynamicTest.ascx"
    > TagName="DynamicTest" %>
    >
    >
    > In the <script /> block...
    >
    > Sub Page_Load(Sender As Object, e As EventArgs)
    >
    > Dim objNew as New DynamicTest '<< Raised Error: BC30002: Type
    > 'DynamicTest' is not defined
    >
    > Controls.Add(objNew)
    >
    > End Sub
    >
    > What I'm doing wrong here? I'm really hitting my head against the wall.

    Plz,
    > anyone could help, I really appreciate it!
    >
    > David
    >
    >
     
    Robert Koritnik, Nov 3, 2004
    #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. David Freeman

    HowTo: Dynamically Add Custom Controls?

    David Freeman, Nov 3, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    521
    Matt Berther
    Nov 3, 2004
  2. Dan Sikorsky
    Replies:
    1
    Views:
    5,883
    Dan Sikorsky
    Feb 17, 2005
  3. Replies:
    0
    Views:
    320
  4. David Freeman

    HowTo: Dynamically Add Custom Controls?

    David Freeman, Nov 3, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    113
    Robert Koritnik
    Nov 3, 2004
  5. rifat yavuz
    Replies:
    0
    Views:
    224
    rifat yavuz
    Jul 4, 2008
Loading...

Share This Page