Building a control that loads its template from a database

Discussion in 'ASP .Net' started by DC, Jan 29, 2007.

  1. DC

    DC Guest


    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

    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,
    DC, Jan 29, 2007
    1. Advertisements

  2. DC

    sticky Guest

    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.
    sticky, Jan 29, 2007
    1. Advertisements

  3. DC

    DC Guest

    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.

    DC, Feb 1, 2007
  4. DC

    marss Guest

    Why not to use a web custom control? Is is more suitable for dinamic
    content loading.
    marss, Feb 1, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.