Loading User controls

Discussion in 'ASP .Net' started by John, Jul 1, 2003.

  1. John

    John Guest

    Hi all,

    I'm having a little problem understanding the concepts of dynamically
    loading/unloading user conrols:

    1. If I have a couple of usercontrols embedded within a few tables cells on
    my page, setting the usercontrol's visible to false still fires the
    Page_Load event. Isn't this unnecessary overhead when it doesn't even show
    in my page.

    2. For my usercontrols to be able to see one another's methods, do I have to
    define the usercontrol within the code-behind of each usercontrol I wish to
    reference?

    3. To dynamically load/unload usercontrols, must I register them at least
    within my page at design-time? This seems 'un-dynamic' to me.

    4. What method do I use to run code the first time my user control is
    dynamically loaded. I don't want to run the code again after that unless it
    is removed then re-loaded again.


    There clearly is much for me to learn about usercontrols. If the above four
    questions could please be answered and perhaps a pointer to some good online
    reading material, I really would appreciate this!

    Thanks.

    Regards
    John.
     
    John, Jul 1, 2003
    #1
    1. Advertising

  2. John

    Marina Guest

    1. Loading a control and making it not visible are 2 different things.
    Invisible controls will not be rendered to the page - but they are still
    created, and their page_load will still fire.

    2. You should define public methods to allow this. You will also need to
    have a way for one control to get a reference to the instance of the other
    control.

    3. To dynamically load controls, you do not need to register anything with
    the page. You can just call the LoadControl method of the page, and then add
    the newly created usercontrol to your page.

    "John" <> wrote in message
    news:euKyBt$...
    > Hi all,
    >
    > I'm having a little problem understanding the concepts of dynamically
    > loading/unloading user conrols:
    >
    > 1. If I have a couple of usercontrols embedded within a few tables cells

    on
    > my page, setting the usercontrol's visible to false still fires the
    > Page_Load event. Isn't this unnecessary overhead when it doesn't even show
    > in my page.
    >
    > 2. For my usercontrols to be able to see one another's methods, do I have

    to
    > define the usercontrol within the code-behind of each usercontrol I wish

    to
    > reference?
    >
    > 3. To dynamically load/unload usercontrols, must I register them at least
    > within my page at design-time? This seems 'un-dynamic' to me.
    >
    > 4. What method do I use to run code the first time my user control is
    > dynamically loaded. I don't want to run the code again after that unless

    it
    > is removed then re-loaded again.
    >
    >
    > There clearly is much for me to learn about usercontrols. If the above

    four
    > questions could please be answered and perhaps a pointer to some good

    online
    > reading material, I really would appreciate this!
    >
    > Thanks.
    >
    > Regards
    > John.
    >
    >
     
    Marina, Jul 1, 2003
    #2
    1. Advertising

  3. Hi John,

    Here is the answer to your queries.
    1. If you are using the register directive to load the
    userconoreol (I mean design time loading), Then page load
    of the suer control will run even if the vicible property
    = false. This is to initialize the control.

    2&3. If you want to dynamically load the user control from
    code behind please use the loadcontrol( ) method with
    refernce to *.ascx file. No need to use both register &
    loadcontrol simultaniously.

    4. If you enbael the page caching for your usercontrol (I
    mean fragment caching) then it wont take much time to load
    the usercontrol next time.

    The following links will be usefull.
    http://samples.gotdotnet.com/quickstart/aspplus/doc/webpage
    lets.aspx
    http://www.codeproject.com/aspnet/aspnetusercontrol2.asp
    http://www.dotnetjohn.com/articles/articleid52.aspx

    regards
    Sreejumon[MVP]
    DOTNET makes IT happen

    >-----Original Message-----
    >Hi all,
    >
    >I'm having a little problem understanding the concepts of

    dynamically
    >loading/unloading user conrols:
    >
    >1. If I have a couple of usercontrols embedded within a

    few tables cells on
    >my page, setting the usercontrol's visible to false still

    fires the
    >Page_Load event. Isn't this unnecessary overhead when it

    doesn't even show
    >in my page.
    >
    >2. For my usercontrols to be able to see one another's

    methods, do I have to
    >define the usercontrol within the code-behind of each

    usercontrol I wish to
    >reference?
    >
    >3. To dynamically load/unload usercontrols, must I

    register them at least
    >within my page at design-time? This seems 'un-dynamic' to

    me.
    >
    >4. What method do I use to run code the first time my

    user control is
    >dynamically loaded. I don't want to run the code again

    after that unless it
    >is removed then re-loaded again.
    >
    >
    >There clearly is much for me to learn about usercontrols.

    If the above four
    >questions could please be answered and perhaps a pointer

    to some good online
    >reading material, I really would appreciate this!
    >
    >Thanks.
    >
    >Regards
    >John.
    >
    >
    >.
    >
     
    Sreejumon[MVP], Jul 1, 2003
    #3
  4. John

    Kurt Guest

    John

    Have you gotten worked out your solution to loading your controls
    dynamically, it sounds like you are having close to the same problrems I am
    having.

    Kurt

    "John" <> wrote in message
    news:euKyBt$...
    > Hi all,
    >
    > I'm having a little problem understanding the concepts of dynamically
    > loading/unloading user conrols:
    >
    > 1. If I have a couple of usercontrols embedded within a few tables cells

    on
    > my page, setting the usercontrol's visible to false still fires the
    > Page_Load event. Isn't this unnecessary overhead when it doesn't even show
    > in my page.
    >
    > 2. For my usercontrols to be able to see one another's methods, do I have

    to
    > define the usercontrol within the code-behind of each usercontrol I wish

    to
    > reference?
    >
    > 3. To dynamically load/unload usercontrols, must I register them at least
    > within my page at design-time? This seems 'un-dynamic' to me.
    >
    > 4. What method do I use to run code the first time my user control is
    > dynamically loaded. I don't want to run the code again after that unless

    it
    > is removed then re-loaded again.
    >
    >
    > There clearly is much for me to learn about usercontrols. If the above

    four
    > questions could please be answered and perhaps a pointer to some good

    online
    > reading material, I really would appreciate this!
    >
    > Thanks.
    >
    > Regards
    > John.
    >
    >
     
    Kurt, Jul 2, 2003
    #4
  5. John

    John Guest

    Hi Kurt,

    I have finally got it working, although now I'm treading water in another
    area (also user control related). If there is anything in particular I could
    help with, let me know.

    Regards
    John.




    "Kurt" <> wrote in message
    news:...
    > John
    >
    > Have you gotten worked out your solution to loading your controls
    > dynamically, it sounds like you are having close to the same problrems I

    am
    > having.
    >
    > Kurt
    >
    > "John" <> wrote in message
    > news:euKyBt$...
    > > Hi all,
    > >
    > > I'm having a little problem understanding the concepts of dynamically
    > > loading/unloading user conrols:
    > >
    > > 1. If I have a couple of usercontrols embedded within a few tables cells

    > on
    > > my page, setting the usercontrol's visible to false still fires the
    > > Page_Load event. Isn't this unnecessary overhead when it doesn't even

    show
    > > in my page.
    > >
    > > 2. For my usercontrols to be able to see one another's methods, do I

    have
    > to
    > > define the usercontrol within the code-behind of each usercontrol I wish

    > to
    > > reference?
    > >
    > > 3. To dynamically load/unload usercontrols, must I register them at

    least
    > > within my page at design-time? This seems 'un-dynamic' to me.
    > >
    > > 4. What method do I use to run code the first time my user control is
    > > dynamically loaded. I don't want to run the code again after that unless

    > it
    > > is removed then re-loaded again.
    > >
    > >
    > > There clearly is much for me to learn about usercontrols. If the above

    > four
    > > questions could please be answered and perhaps a pointer to some good

    > online
    > > reading material, I really would appreciate this!
    > >
    > > Thanks.
    > >
    > > Regards
    > > John.
    > >
    > >

    >
    >
     
    John, Jul 2, 2003
    #5
    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. Kevin Spencer

    Loading a user controls in Design View

    Kevin Spencer, Jul 24, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    420
    oneeye
    Jul 29, 2003
  2. =?Utf-8?B?V291dGVy?=

    Dynamically Loaded controls loading other controls

    =?Utf-8?B?V291dGVy?=, Feb 27, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    518
    =?Utf-8?B?V291dGVy?=
    Feb 27, 2006
  3. Bob Rock
    Replies:
    1
    Views:
    690
    Cowboy \(Gregory A. Beamer\)
    Sep 17, 2006
  4. Faizan Ahmed
    Replies:
    1
    Views:
    312
    John Saunders
    Jan 4, 2005
  5. Faizan Ahmed
    Replies:
    1
    Views:
    390
    John Saunders
    Jan 4, 2005
Loading...

Share This Page