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. Dynamic.. Dynamic.. User Controls.

Dynamic.. Dynamic.. User Controls.

Scheduled Pinned Locked Moved ASP.NET
databasewinformsxmlquestion
3 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.
  • R Offline
    R Offline
    Rocky Moore
    wrote on last edited by
    #1

    Is there some way to create a user control (ascx) dynamically? I know you can LoadControl() but to access any of the properties, I have to <%@ Reference...%> or <%@ Register ..%> the controls on the page before they are used. Is there some method to acheive that same functionality in the Code Behind? I would like to have a definition in a database or XML file to swap modules in our out without having to add a Ref in the aspx page for every possible user control I want to use. Any ideas? I know it it probably something simple, just blind ;) Rocky Moore <><

    N 1 Reply Last reply
    0
    • R Rocky Moore

      Is there some way to create a user control (ascx) dynamically? I know you can LoadControl() but to access any of the properties, I have to <%@ Reference...%> or <%@ Register ..%> the controls on the page before they are used. Is there some method to acheive that same functionality in the Code Behind? I would like to have a definition in a database or XML file to swap modules in our out without having to add a Ref in the aspx page for every possible user control I want to use. Any ideas? I know it it probably something simple, just blind ;) Rocky Moore <><

      N Offline
      N Offline
      neroknights
      wrote on last edited by
      #2

      If I am understanding correctly, you use LoadControl in the page load or the init handler and cast it to your user control class. You will now have all the properties avaialable to you including all controls within that user control. Be careful however, if you cache the user control the control that is returned to you from the LoadControl method will be a PartialCachingControl which I am unable to find a way to retrieve any of the properties. I just made a post after you as why is this the case.

      R 1 Reply Last reply
      0
      • N neroknights

        If I am understanding correctly, you use LoadControl in the page load or the init handler and cast it to your user control class. You will now have all the properties avaialable to you including all controls within that user control. Be careful however, if you cache the user control the control that is returned to you from the LoadControl method will be a PartialCachingControl which I am unable to find a way to retrieve any of the properties. I just made a post after you as why is this the case.

        R Offline
        R Offline
        Rocky Moore
        wrote on last edited by
        #3

        neroknights wrote: you use LoadControl in the page load or the init handler and cast it to your user control class Yeah, that was the problem, it requires the <%@ Reference..%> to so that it knows the format that you are casting to. If you have say, 50 controls you might be using, it would be a pain to put the <%@ Refrerence.. %> for every control you "might" use on each page that "might" use them. neroknights wrote: PartialCachingControl Was just heading down that road shortly ;) Rocky Moore <><

        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