PDA

View Full Version : How do you include custom user controls in content page?


hotwheelharry
06-30-2009, 07:26 PM
I created a custom user control "CustomControl" and I want to reference it in the code behind of a content page.

The reason is because I need to generate a bunch of these custom controls on the content page so i can't include them by doing <tag:CustomControl />.

I need to be able to do

CustomControl myCtrl = new CustomControl();
Page.Controls.Add(myCtrl);
//repeat x times

on the code behind of the content page.

I can't get it to work!

So far I have...
Default settings on content page & on the control.

AND a reference to the control on the content page like...
<%@ Reference Control="~/Controls/CustomControl.ascx" %>


But when I try to create one of these controls in content page code behind it throws an error because it can't find CustomControl.

Sorry about the length of this, I wanted to be thorough.
Any help appreciated! :D

Mike_O
06-30-2009, 10:23 PM
Hey hotwheelharry,

This link pretty much sums it up:

http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/userctrl/default.aspx

Mike

hotwheelharry
07-01-2009, 03:57 PM
Thanks Mike,
The article sure did sum it up. I fixed the problem. :thumbsup: