Building a control that loads its template from a database

  • Thread starter Thread starter DC
  • Start date Start date
D

DC

Hi,

I have the requirement to build a control that will read its template
from a database. (I call all the stuff one would normally place
between the start and end tag of a placeholder in a usercontrol
"template" here.) The purpose is to provide HTML snippets with the
ability tho change the .ascx part without manipulating and deploying
files.

I see the TemplateControl class and its "LoadTemplate" control but
that seems to load from a physical path only (I am restricted to
framework 1.1). Does someone know an approach or a code sample for
what I want to do?

TIA for any hint,
Regards
DC
 
that could be complicated

if you just want to display static html, with no .net controls, then
try overriding the render method for the control and outputting the
stored template then.

if you want to have controls in your usercontrol, and do things like
saving their viewstate then things will become a lot more complicated.

you could try serializing the controls to the database and then
deserializing them and loading them (you have to do this on page_init
for them to be automatically added to the viewstate)

you can also dynamically create user controls, which could be the
easiest way i think


its difficult to know what is the best option with out more
information on what you are trying to do.
 
Thanks sticky,

I did not find a proper way to load templates without using file
access. I therefore changed the requirements and will load the ascx
from a file now (LoadControl). My main intent is that the ascx code is
kept in a database, so I will implement a mechanism to sync the data
with a .ascx file.

Regards
DC
 
DC said:
Hi,

I have the requirement to build a control that will read its template
from a database. (I call all the stuff one would normally place
between the start and end tag of a placeholder in a usercontrol
"template" here.) The purpose is to provide HTML snippets with the
ability tho change the .ascx part without manipulating and deploying
files.

Why not to use a web custom control? Is is more suitable for dinamic
content loading.
http://msdn.microsoft.com/library/d...l/vbconwebusercontrolsvscustomwebcontrols.asp
 
Back
Top