Loading User controls

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Loading User controls

    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 Guest

  2. Similar Questions and Discussions

    1. using javascript in User controls to access server controls of the user control
      Hello all, I have an asp.net textbox (named txtHidden) and an HtmlButton(named btnAction). I wanted to write a javascript function which will get...
    2. Loading user controls many times in a page is a good solution?
      Hi, One of the features in my project is to show the content one by one. We have several types of content, such as "Articles", "Books", "Images"...
    3. Loading Different User Controls into a Single DataGrid
      I have a situation where I am going to create 5 similar, but different user controls that all need to be bound into one datagrid. Basically,...
    4. Loading/Unloading web user controls dynamically in code - Does this look right?
      You ought to check out the DynamicPlaceHolder control instead of using the builtin Placeholder. ...
    5. Loading a user controls in Design View
      Not sure I understand you fully, but it sounds like you want to build a custom Designer for your control. If so, see: ...
  3. #2

    Default Re: Loading User controls

    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" <a@b.com> wrote in message
    news:euKyBt$PDHA.1608@TK2MSFTNGP11.phx.gbl...
    > 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 Guest

  4. #3

    Default Loading User controls

    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.
    [url]http://samples.gotdotnet.com/quickstart/aspplus/doc/webpage[/url]
    lets.aspx
    [url]http://www.codeproject.com/aspnet/aspnetusercontrol2.asp[/url]
    [url]http://www.dotnetjohn.com/articles/articleid52.aspx[/url]

    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] Guest

  5. #4

    Default Re: Loading User controls

    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" <a@b.com> wrote in message
    news:euKyBt$PDHA.1608@TK2MSFTNGP11.phx.gbl...
    > 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 Guest

  6. #5

    Default Re: Loading User controls

    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.

    [email]finnej00REMOVETHIS@hotmail.com[/email]


    "Kurt" <k_nojunk@larimore.net> wrote in message
    news:edDUdfMQDHA.704@tk2msftngp13.phx.gbl...
    > 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" <a@b.com> wrote in message
    > news:euKyBt$PDHA.1608@TK2MSFTNGP11.phx.gbl...
    > > 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 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139