Can you load a usercontrol into another usercontrol?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • COHENMARVIN@lycos.com

    Can you load a usercontrol into another usercontrol?

    I have an aspx page that loads a usercontrol. Can that usercontrol
    load another usercontrol into part of it?
    Thanks,
    Marv
  • George Ter-Saakov

    #2
    Re: Can you load a usercontrol into another usercontrol?

    Sure, why not....

    George.

    <COHENMARVIN@ly cos.comwrote in message
    news:a1802d18-0b26-421f-b0e3-108c0125b31a@j2 2g2000hsf.googl egroups.com...
    >I have an aspx page that loads a usercontrol. Can that usercontrol
    load another usercontrol into part of it?
    Thanks,
    Marv

    Comment

    • Mark Fitzpatrick

      #3
      Re: Can you load a usercontrol into another usercontrol?

      Yes, just keep in mind that you need to time your events well in the control
      event hierarchy. Sometimes an action in a usercontrol that works when
      embedded in a page may be a bit off when placed inside another user control.
      For example, you pass data from a usercontrol to another one that will show
      some more data. You click a link in the parent usercontrol to select a
      different set of data to show in the child usercontrol, but the timing of
      the events is off so the child usercontrol doesn't update properly and ends
      up a step behind the parent.

      Hope this helps,
      Mark Fitzpatrick
      Microsoft MVP - Expression

      <COHENMARVIN@ly cos.comwrote in message
      news:a1802d18-0b26-421f-b0e3-108c0125b31a@j2 2g2000hsf.googl egroups.com...
      I have an aspx page that loads a usercontrol. Can that usercontrol
      load another usercontrol into part of it?
      Thanks,
      Marv

      Comment

      • Arthur

        #4
        Re: Can you load a usercontrol into another usercontrol?

        how do you want to load it?
        1.dynamicaly in code behind or
        2.insert usercontrol tag in aspx/ascx code?

        ad 1)
        place the folowing directive in the asp code of the parent page or
        usercontrol:

        <%@ Reference Control="~/Name_of_your_ch ild_control.asc x" %>


        create a new instance in code behind by the following code:

        Name_of_your_ch ild_control control = (Name_of_your_c hild_control)
        TemplateControl .LoadControl("~/Name_of_your_ch ild_control.asc x");



        ad 2)
        place the folowing directive in the asp code of the parent page or
        usercontrol:

        <%@ Register src="Name_of_yo ur_child_contro l.ascx"
        tagname="Name_o f_your_child_co ntrol" tagprefix="uc1" %>


        use the following tag in the asp-code of the parent page/control:

        <uc1:Name_of_yo ur_child_contro l ID="Name_of_you r_child_control 1"
        runat="server" />

        Comment

        Working...