Is there a way to reuse dynamic controls with multiple parents?

Discussion in 'ASP .Net' started by Homam, Mar 4, 2005.

  1. Homam

    Homam Guest

    So I have a composite paging control that shoulld be positioned on the page
    like this:

    PagNav
    ResultSetDisplay
    PagNav

    I know that I can't resuse the PagNav more than once in the form, so I
    instantiate a couple of instances, PagNavTop and PagNavBottom, and thus I
    end up with:

    PagNavTop
    ResultSetDisplay
    PagNavBottom

    The paging navigators are composed of a bunch of dynamically generated
    LinkButtons and Lables. And since they should appear on the page
    identically, I don't want to do the extra dynamic control creation and
    calculation for the bottom one. I thought I might just re-use the same
    LinkButtons and Labels in both top and bottom.

    Alas, the ASP.NET framework boobytraps the dynamic controls if they're added
    to another control ini the same form. Once I add them to PagNavBottom --
    after adding them to PagNavTop -- they vanish from PagNavTop and will only
    show up in the last parent they've been added to, PagNavBottom.

    It's waste of processor cycles and memory to recreate a brand new set of
    controls to each parent. I'm pretty sure that many people here in this group
    have bumped into this issue, and I appreciate your feedback on how you'd
    attack such a problem.

    Homam
     
    Homam, Mar 4, 2005
    #1
    1. Advertising

  2. Homam

    Homam Guest

    I found out this is not possible: In ASP.NET, each control points to a
    single parent. So we have the parent pointing to all the children
    (Control.Controls) in addition to the child pointing up to the parent
    (Control.Parent). That's why the control will always point to the last
    parent it's been added to.

    The quick and dirty solution is to render the controls as static HTML string
    and reuse that in both places.

    But I'm curious if there are neater yet efficient ways to do it.



    "Homam" <> wrote in message
    news:...
    > So I have a composite paging control that shoulld be positioned on the
    > page like this:
    >
    > PagNav
    > ResultSetDisplay
    > PagNav
    >
    > I know that I can't resuse the PagNav more than once in the form, so I
    > instantiate a couple of instances, PagNavTop and PagNavBottom, and thus I
    > end up with:
    >
    > PagNavTop
    > ResultSetDisplay
    > PagNavBottom
    >
    > The paging navigators are composed of a bunch of dynamically generated
    > LinkButtons and Lables. And since they should appear on the page
    > identically, I don't want to do the extra dynamic control creation and
    > calculation for the bottom one. I thought I might just re-use the same
    > LinkButtons and Labels in both top and bottom.
    >
    > Alas, the ASP.NET framework boobytraps the dynamic controls if they're
    > added to another control ini the same form. Once I add them to
    > PagNavBottom -- after adding them to PagNavTop -- they vanish from
    > PagNavTop and will only show up in the last parent they've been added to,
    > PagNavBottom.
    >
    > It's waste of processor cycles and memory to recreate a brand new set of
    > controls to each parent. I'm pretty sure that many people here in this
    > group have bumped into this issue, and I appreciate your feedback on how
    > you'd attack such a problem.
    >
    > Homam
    >
    >
     
    Homam, Mar 4, 2005
    #2
    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. tshad
    Replies:
    5
    Views:
    539
    Steve C. Orr [MVP, MCSD]
    May 17, 2005
  2. Hylander

    To reuse or not to reuse....

    Hylander, Feb 26, 2004, in forum: Java
    Replies:
    0
    Views:
    424
    Hylander
    Feb 26, 2004
  3. The alMIGHTY N
    Replies:
    1
    Views:
    627
    Joris Gillis
    Feb 9, 2007
  4. code reuse and design reuse

    , Feb 7, 2006, in forum: C Programming
    Replies:
    16
    Views:
    1,032
    Malcolm
    Feb 12, 2006
  5. jacob navia

    To reuse or not to reuse

    jacob navia, Nov 5, 2006, in forum: C Programming
    Replies:
    19
    Views:
    533
    Dave Thompson
    Dec 18, 2006
Loading...

Share This Page