Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Inserting a Web User Control at runtime

Inserting a Web User Control at runtime

Scheduled Pinned Locked Moved ASP.NET
helpcsharpwinforms
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andrei Ungureanu
    wrote on last edited by
    #1

    Hello, I'll get rigth to the point. In my asp .net website I created a few user controls (files with 'ascx' extension). My problem is that I tried in many ways to insert one of these controls on an aspx page at runtime depending on some triggers (let's say) and I didn't succede. Please help me with an idea or anything. Thanks in advance :)

    J 1 Reply Last reply
    0
    • A Andrei Ungureanu

      Hello, I'll get rigth to the point. In my asp .net website I created a few user controls (files with 'ascx' extension). My problem is that I tried in many ways to insert one of these controls on an aspx page at runtime depending on some triggers (let's say) and I didn't succede. Please help me with an idea or anything. Thanks in advance :)

      J Offline
      J Offline
      Jakob Farian Krarup
      wrote on last edited by
      #2

      You can load a usercontrol dynamically using the Page's LoadControl method. So you just need some place to add the control. A PlaceHolder control is perfect for this. Drag the PlaceHolder on to the place where you want to load the user control. Then use the code

      Control userControl = Page.LoadControl("myUserControl.ascx");
      placeHolder1.Controls.Add(userControl);

      I don't think there's a limit to the nesting of usercontrols within usercontrols, but I could be wrong Kind regards - Jakob :cool: Three kinds of people in the world: - Those who can count.. - Those who can't!

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups