Click here to Skip to main content
13,287,573 members (46,793 online)
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 17 May 2006

ParseControl during runtime with a custom control

, 17 May 2006
Rate this:
Please Sign up or sign in to vote.
Using ParseControl during runtime with a custom control.


ASP.NET 2.0 has made the use of master/details page inheritance much easier. It has, however, introduced some extra points to keep in mind while working with master/details pages. The ParseControl method is probably not the most difficult method to use, but if you want to render a custom control that is not part of the .NET framework, then you have to keep in mind to register the control on the page during runtime before rendering the control itself.


I was recently trying to split web page content from the actual web page design. This led me to save the content in a database and have the page layout in a master/details page structure. To make life easier, I created custom controls with the additional functionality that was needed on the separate pages.

I did, however, get stuck while trying to render the controls during runtime. Even though I registered the custom controls in the master and details pages during design time, I kept getting a server error: "Unknown server tag...".

The solution is simple, if you know what you are looking for...

Using the Code

As I was working with master/details pages, I first had to get a reference to the ContentPlaceHolder of the master page during runtime from the details page:

Dim PlaceHolder1 As ContentPlaceHolder = Master.FindControl("ContentPlaceHolder1")

Next, declare a control of type Control and call the ParseControl method to assign the value of the custom control to the newly created control:

Dim c As Control
c = ParseControl("<search:searchbox ID="Searchbox" runat="server" />")

Add the newly created control to the ContentPlaceHolder control:


As I mentioned at the beginning of the article, you first have to register the control on the page before you add the control.

Amend the ParseControl statement and add the @register directive that references your custom control.

c = ParseControl("<%@ register tagprefix="search" tagname="searchbox" " & _
   "src="~/searchresults.ascx" %><search:searchbox ID="Searchbox" runat="server" />")

Points of Interest

ParseControl accepts any HTML that you throw at it. You can therefore save the entire page's HTML in a database field and render it during runtime by parsing it out.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Program Manager
South Africa South Africa
Stuck with a desk job by day, but an entrepreneur, software developer and internet marketer by night. I own a South African retail site - - and have been involved in a number of web ecommerce projects. ASP.Net being my main technology of choice while building on MOSS 2010.

You may also be interested in...


Comments and Discussions

GeneralGood Artical Pin
satishkulala99927-Feb-12 2:26
membersatishkulala99927-Feb-12 2:26 
Questionwhat about partial caching? Pin
theJazzyBrain24-Nov-06 1:32
membertheJazzyBrain24-Nov-06 1:32 
QuestionParseControl namespace? Pin
Kirk Quinbar24-May-06 10:24
memberKirk Quinbar24-May-06 10:24 
AnswerRe: ParseControl namespace? [modified] Pin
RayBez25-May-06 10:13
memberRayBez25-May-06 10:13 
GeneralDifference to LoadControl Pin
TrendyTim23-May-06 17:14
memberTrendyTim23-May-06 17:14 
GeneralRe: Difference to LoadControl Pin
RayBez25-May-06 10:09
memberRayBez25-May-06 10:09 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171207.1 | Last Updated 18 May 2006
Article Copyright 2006 by RayBez
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid