dynamically loading usercontrol

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Guest's Avatar

    #1

    dynamically loading usercontrol

    Hello all,

    I have a UserControl that renders some HTML content. I now need to
    dynamically load and render "n" instances of this usercontrol on a host aspx
    page inside a panel control based upon user input of "n". Any ideas how I
    can do this?

    TIA!


  • Eliyahu Goldin

    #2
    Re: dynamically loading usercontrol

    You need to use a databound control, perhaps a repeater, that will be bound
    to a datasource, perhaps an array, containing all instances of the user
    control.

    Have some code that will creat an array myControls[] based on the user
    input. Then do
    myRepeater.Data Source = myControls;
    myRepeater.Data Bind();



    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]




    <param@communit y.nospamwrote in message
    news:e$cBt4XXIH A.1164@TK2MSFTN GP02.phx.gbl...
    Hello all,
    >
    I have a UserControl that renders some HTML content. I now need to
    dynamically load and render "n" instances of this usercontrol on a host
    aspx page inside a panel control based upon user input of "n". Any ideas
    how I can do this?
    >
    TIA!
    >

    Comment

    • =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=

      #3
      RE: dynamically loading usercontrol

      Howdy,

      Use Repeater or DataList:

      -- aspx code --
      <asp:Repeater runat="server" ID="dynamicCont rols">
      <ItemTemplate >
      <uc1:myUserCont rol runat="server" ID="myUserContr ol"/>
      </ItemTemplate>
      </asp:Repeater>
      -- c# code beside --
      protected void Page_Load(objec t sender, EventArgs e)
      {
      if (!IsPostBack)
      {
      int rowCount = 10;
      myRepeater.Data Source = new int[rowCount];
      myRepeater.Data Bind();
      }
      }

      Hope it helps
      --
      Milosz


      "param@communit y.nospam" wrote:
      Hello all,
      >
      I have a UserControl that renders some HTML content. I now need to
      dynamically load and render "n" instances of this usercontrol on a host aspx
      page inside a panel control based upon user input of "n". Any ideas how I
      can do this?
      >
      TIA!
      >
      >
      >

      Comment

      • Guest's Avatar

        #4
        Re: dynamically loading usercontrol

        OK,

        Thanks for the tip. Now, what if I need to set custom properties on my
        usercontrol. Is that possible?

        TIA!

        "Milosz Skalecki [MCAD]" <mily242@DONTLI KESPAMwp.plwrot e in message
        news:B89DDECD-A644-4935-AC3C-1501108EB518@mi crosoft.com...
        Howdy,
        >
        Use Repeater or DataList:
        >
        -- aspx code --
        <asp:Repeater runat="server" ID="dynamicCont rols">
        <ItemTemplate >
        <uc1:myUserCont rol runat="server" ID="myUserContr ol"/>
        </ItemTemplate>
        </asp:Repeater>
        -- c# code beside --
        protected void Page_Load(objec t sender, EventArgs e)
        {
        if (!IsPostBack)
        {
        int rowCount = 10;
        myRepeater.Data Source = new int[rowCount];
        myRepeater.Data Bind();
        }
        }
        >
        Hope it helps
        --
        Milosz
        >
        >
        "param@communit y.nospam" wrote:
        >
        >Hello all,
        >>
        >I have a UserControl that renders some HTML content. I now need to
        >dynamically load and render "n" instances of this usercontrol on a host
        >aspx
        >page inside a panel control based upon user input of "n". Any ideas how I
        >can do this?
        >>
        >TIA!
        >>
        >>
        >>

        Comment

        Working...