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