dynamic user controls in compiled site

Discussion in 'ASP .Net' started by germ, May 4, 2007.

  1. germ

    germ Guest

    I am moving a web application from 1.1 to 2.0
    This site builds pages dynamically as :
    PlaceHolder.Controls.Add(LoadControl("~/Controls/Ctl1.ascx"));
    Everything is working fine as long as the web site is updateable - the .ascx
    files exist on disk.
    I would like to use the non-updateable and single assembly options - no
    ..ascx files.

    I thought that maybe this would work :
    PlaceHolder.Controls.Add(LoadControl("AppNameSpace.Controls.Ctl1",null));
    This creates the proper object as defined by the code behind class.
    However it never creates any child controls - textboxes etc.

    Is there an additional step required to instantiate the page controls ?
    Is there a class for the .ascx half of the control that I should be loading
    instead ?

    ...

    Gerry
     
    germ, May 4, 2007
    #1
    1. Advertising

  2. germ

    bruce barker Guest

    if you pass a string to LoadControl, it wants the path to the file. to
    load from the assembly, you need to pass the type and construction
    parameters.


    PlaceHolder.Controls.Add(
    LoadControl(typeof(MyControlClassName),null));

    be sure to specify the class name in the page directive.


    -- bruce (sqlwork.com)

    germ wrote:
    > I am moving a web application from 1.1 to 2.0
    > This site builds pages dynamically as :
    > PlaceHolder.Controls.Add(LoadControl("~/Controls/Ctl1.ascx"));
    > Everything is working fine as long as the web site is updateable - the .ascx
    > files exist on disk.
    > I would like to use the non-updateable and single assembly options - no
    > .ascx files.
    >
    > I thought that maybe this would work :
    > PlaceHolder.Controls.Add(LoadControl("AppNameSpace.Controls.Ctl1",null));
    > This creates the proper object as defined by the code behind class.
    > However it never creates any child controls - textboxes etc.
    >
    > Is there an additional step required to instantiate the page controls ?
    > Is there a class for the .ascx half of the control that I should be loading
    > instead ?
    >
    > ...
    >
    > Gerry
    >
    >
     
    bruce barker, May 5, 2007
    #2
    1. Advertising

  3. germ

    germ Guest

    thanks bruce

    I am using LoadControl(typeof("MyControls.MyCtl"),null);
    and this does create the proper control. however no child controls are
    never created.
    I tried calling CreateChildControls() in the user control OnInit &
    OnPrerender methods after which Controls collection is always empty.

    by "specify the class name in the page directive" - do you mean in the user
    ..ascx Control directive ? or in a Register directive on the .aspx ?
    The Control directive looks like this : <%@ Control Language="c#"
    AutoEventWireup="True" Codebehind="MyCtl.ascx.cs"
    Inherits="MyControls.MyCtl"
    TargetSchema="http://schemas.microsoft.com/intellisense/nav4-0" %>

    using the Register directive on the page defeats the whole purpose of
    dynamic control creation.

    gerry



    "bruce barker" <> wrote in message
    news:...
    > if you pass a string to LoadControl, it wants the path to the file. to
    > load from the assembly, you need to pass the type and construction
    > parameters.
    >
    >
    > PlaceHolder.Controls.Add(
    > LoadControl(typeof(MyControlClassName),null));
    >
    > be sure to specify the class name in the page directive.
    >
    >
    > -- bruce (sqlwork.com)
    >
    > germ wrote:
    >> I am moving a web application from 1.1 to 2.0
    >> This site builds pages dynamically as :
    >> PlaceHolder.Controls.Add(LoadControl("~/Controls/Ctl1.ascx"));
    >> Everything is working fine as long as the web site is updateable - the
    >> .ascx files exist on disk.
    >> I would like to use the non-updateable and single assembly options - no
    >> .ascx files.
    >>
    >> I thought that maybe this would work :
    >> PlaceHolder.Controls.Add(LoadControl("AppNameSpace.Controls.Ctl1",null));
    >> This creates the proper object as defined by the code behind class.
    >> However it never creates any child controls - textboxes etc.
    >>
    >> Is there an additional step required to instantiate the page controls ?
    >> Is there a class for the .ascx half of the control that I should be
    >> loading instead ?
    >>
    >> ...
    >>
    >> Gerry
     
    germ, May 5, 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. Earl Teigrob
    Replies:
    4
    Views:
    446
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Apr 4, 2004
  2. Ronald
    Replies:
    2
    Views:
    876
    Robbe Morris [C# MVP]
    Jan 17, 2006
  3. Klaus Schneider
    Replies:
    1
    Views:
    584
    Rolf Magnus
    Dec 2, 2004
  4. lander
    Replies:
    5
    Views:
    627
    bruce barker
    Mar 5, 2008
  5. Denny Smolinski via .NET 247

    Dynamic Controls, Placeholder, Retrieve Information from Dynamic Controls

    Denny Smolinski via .NET 247, May 4, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    510
    Eidolon
    May 4, 2004
Loading...

Share This Page