• Advertisement
Sign in to follow this  

[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.

If you intended to correct an error in the post then please contact us.

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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement