• 13
• 10
• 27
• 9
• 9

# [web] ASP.Net - Generic user control

This topic is 3189 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've made an ASP.Net user control that accepts a generic type. Because of this, I have to dynamically add the control to the page. I've decided to use a PlaceHolder to do this. However, I cannot get the control to render. This is what I'm trying to do:
RuleSetControl<ActionControl> ruleSetControl = LoadControl(typeof(RuleSetControl<ActionControl>), null) as RuleSetControl<ActionControl>;


RuleSetControl is the control that I've created, and ActionControl is the control that I wish to pass to it as a generic. This compiles, but nothing shows up on the screen. I've determined that the problem is that overload to LoadControl, as when testing the following with my very basic ActionControl (which just contains a button):
Control actionControl = LoadControl("ActionControl.ascx"); // This renders the control when added to the PlaceHolder
Control actionControl = LoadControl(typeof(ActionControl), null); // This does not


I've seen others run into this same problem, and the response always seems to be "Just use the overload that takes a string". That doesn't work for me, as there's no way to specify the generic type like that. Does anybody either: 1. What I need to get the overload of LoadControl that takes a type to work properly or 2. How else I can get a generic user control on screen? Thank you.