Click here to Skip to main content
11,920,156 members (59,065 online)
Click here to Skip to main content
Add your own
alternative version


40 bookmarked

Dynamically Loading User Control on a Webform using PlaceHolder control

, 5 Aug 2004
Rate this:
Please Sign up or sign in to vote.
Dynamically loading a User Control on a webform using PlaceHolder control.


In this article, I will explain how to load UserControls programmatically on your webform. First, drag and drop a PlaceHolder control on your webform on which you will load the actual UserControl.

Adding Directive on a Webform

First, you need to add a directive on a webform telling the webform that you are going to dynamically load the usercontrol. So in the webform, add the following directive:

<%@ Reference Control = "WebUserControl1.ascx" %>

Once this directive has place, you need to load the actual control in the webform. You can load the control anywhere in the form. A good place will be the Page_Init event. In the example, I have loaded the control in the Page_Load event.

    WebUserControl1 uc = 
      (WebUserControl1) Page.LoadControl("WebUserControl1.ascx"); 

Here in the code, WebUserControl1 is the name of the UserControl class through which we have created an instance namely "uc". The Page.LoadControl loads the control on the page. And finally the place holder control adds the control to its collection and displays it on the webform.


You can always use drag and drop features of the usercontrol to include it on the page. But sometimes it's important to load when some event occurs in the application, and for that you can create the controls dynamically.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
United States United States
I am the founder of knowledge base website, HighOnCoding, GridViewGuy, and

HighOnCoding is a website which will get you high legally with useful information. There are tons of articles, videos and podcasts hosted on HighOnCoding.

My Blog:


Buy my iPhone app ABC Pop

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
eshaq21-Nov-13 13:58
membereshaq21-Nov-13 13:58 
GeneralMy vote of 1 Pin
ii_noname_ii25-Mar-13 2:08
memberii_noname_ii25-Mar-13 2:08 
QuestionSet "ID" Pin
Hossein Montazeri4-May-12 20:23
memberHossein Montazeri4-May-12 20:23 
GeneralMy vote of 5 Pin
wmtimka12-Apr-12 11:11
memberwmtimka12-Apr-12 11:11 
Questionmain page getting refreshed Pin
praveenkumar palla23-Feb-11 19:19
memberpraveenkumar palla23-Feb-11 19:19 
GeneralDoesn't Work Pin
shauncollege7-Jan-11 4:48
membershauncollege7-Jan-11 4:48 
GeneralMy vote of 1 Pin
Howard Richards6-Nov-10 1:28
memberHoward Richards6-Nov-10 1:28 
GeneralMy vote of 1 Pin
avin0379-Aug-10 2:50
memberavin0379-Aug-10 2:50 
GeneralMy vote of 2 Pin
Ryan Leeder21-Jun-10 20:20
memberRyan Leeder21-Jun-10 20:20 
GeneralMy vote of 1 Pin
mynkow18-Mar-10 6:29
membermynkow18-Mar-10 6:29 
Generaldynamically loading usercontrol Pin
sifad12-Jun-09 8:56
membersifad12-Jun-09 8:56 
GeneralUse jQuery Pin
sjmueller22-Dec-08 21:35
membersjmueller22-Dec-08 21:35 
GeneralSolution to PostBack unload issue Pin
Daniel Saidi15-Jul-08 6:21
memberDaniel Saidi15-Jul-08 6:21 
GeneralPoor Pin
António Barroso20-Sep-07 20:29
memberAntónio Barroso20-Sep-07 20:29 
GeneralRe: Poor Pin
Member 368254825-Feb-09 12:26
memberMember 368254825-Feb-09 12:26 
QuestionThen... what happens with the evens inside the user control? Pin
jbmixed10-Mar-07 1:33
memberjbmixed10-Mar-07 1:33 
GeneralApu explains how to make a squishy... Pin
lexodus6-Mar-07 6:36
memberlexodus6-Mar-07 6:36 
Questioncontrol loaded twice into one placeholder in 2.0 Pin
Pongsuriya15-Aug-06 17:12
memberPongsuriya15-Aug-06 17:12 
AnswerRe: control loaded twice into one placeholder in 2.0 Pin
Alexander Marinov12-Oct-07 4:22
memberAlexander Marinov12-Oct-07 4:22 
GeneralNot Dynamic ... Pin
WaleedS13-May-06 23:37
memberWaleedS13-May-06 23:37 
GeneralRe: Not Dynamic ... Pin
enteng.kabisote14-Nov-06 16:08
memberenteng.kabisote14-Nov-06 16:08 
GeneralRe: Not Dynamic ... Pin
Banaan_12317-Dec-06 22:13
memberBanaan_12317-Dec-06 22:13 
GeneralRe: Not Dynamic ... Pin
smithersgs25-Jan-07 5:24
membersmithersgs25-Jan-07 5:24 
GeneralRe: Not Dynamic ... Pin
Ritesh Totlani20-Aug-10 1:05
memberRitesh Totlani20-Aug-10 1:05 
Generalload a control without a reference Pin
cipcipcode14-Feb-06 6:57
membercipcipcode14-Feb-06 6:57 
GeneralHowto: load a control without a reference Pin
Jon-W21-Mar-07 5:13
memberJon-W21-Mar-07 5:13 
QuestionWhat's next? Showing how to add two numbers? Pin
Anonymous7-Mar-05 14:34
sussAnonymous7-Mar-05 14:34 
AnswerRe: What's next? Showing how to add two numbers? Pin
eliakaris22-Apr-05 13:39
membereliakaris22-Apr-05 13:39 
AnswerRe: What's next? Showing how to add two numbers? Pin
Jason Webb2-May-05 16:14
memberJason Webb2-May-05 16:14 
GeneralRe: What's next? Showing how to add two numbers? Pin
SRL126-May-05 10:15
sussSRL126-May-05 10:15 
GeneralI found this helpful. Pin
eddie122087-Jun-05 6:49
membereddie122087-Jun-05 6:49 
GeneralRe: What's next? Showing how to add two numbers? Pin
Karell24-Nov-05 9:32
memberKarell24-Nov-05 9:32 
GeneralRe: What's next? Showing how to add two numbers? Pin
Jason Webb24-Nov-05 16:00
memberJason Webb24-Nov-05 16:00 
GeneralRe: What's next? Showing how to add two numbers? Pin
Indirection17-Mar-06 7:52
memberIndirection17-Mar-06 7:52 
GeneralRe: What's next? Showing how to add two numbers? Pin
granig30-Jan-07 6:33
membergranig30-Jan-07 6:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151120.1 | Last Updated 6 Aug 2004
Article Copyright 2004 by azamsharp
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid