Dynamic User Controls

Discussion in 'ASP .Net' started by anthonyroche, Sep 22, 2004.

  1. anthonyroche

    anthonyroche Guest

    I have a web app (ASP.Net) using Templates with predominatly the body
    content stored in the db and displayed to screen using a PageID
    querystring. What I want to know is, if a content manager adds the
    tags
    <wuc:news id="News" runat="server"></wuc:news> into the body section
    via a CMS together with other page data (HTML content), how can I
    detect this tag (user control) and actually load it in the place
    he/she wants.
    Example HTML content loaded from db

    <table><tr><td>some text here</td></tr>
    <tr><td> more text maybe with images</td></tr>
    <!-- NOW I WANT THE NEWS USER CONTROL -->
    <tr><td><wuc:news id="News" runat="server"></wuc:news></td></tr>
    </table>

    I use a placeholder on the template page to pick up the string(above)
    that is stored in the DB which works fine. When I view source I can
    see the <wuc.. tag but ofcourse the news control is not rendered or
    loaded.

    Any ideas?
     
    anthonyroche, Sep 22, 2004
    #1
    1. Advertising

  2. Hi,

    You will have to parse the "html" (which happens to be a little bit more
    than html) and add the controls by yourself. Let's suppose you have a method
    that renders the "html" in question with the following signature:

    public void Render(string content, HtmlTextWriter writer){}

    You will have to parse the string in content. So, when you find pure html
    (for direct output) do:

    writer.Write(pureHtml);

    When you find some control (i.e. WUCNews) you will have to first instantiate
    it from the corresponding class:

    WUCNews news1 = new WUCNews();

    Then probably set some properties (you might need to parse some attributes):

    news1.Page = Page;
    news1.EnableViewState = false;
    // etc...

    And in the end render it:

    news1.RenderControl(writer);

    Hope this helps
    Martin

    "anthonyroche" <> wrote in message
    news:...
    > I have a web app (ASP.Net) using Templates with predominatly the body
    > content stored in the db and displayed to screen using a PageID
    > querystring. What I want to know is, if a content manager adds the
    > tags
    > <wuc:news id="News" runat="server"></wuc:news> into the body section
    > via a CMS together with other page data (HTML content), how can I
    > detect this tag (user control) and actually load it in the place
    > he/she wants.
    > Example HTML content loaded from db
    >
    > <table><tr><td>some text here</td></tr>
    > <tr><td> more text maybe with images</td></tr>
    > <!-- NOW I WANT THE NEWS USER CONTROL -->
    > <tr><td><wuc:news id="News" runat="server"></wuc:news></td></tr>
    > </table>
    >
    > I use a placeholder on the template page to pick up the string(above)
    > that is stored in the DB which works fine. When I view source I can
    > see the <wuc.. tag but ofcourse the news control is not rendered or
    > loaded.
    >
    > Any ideas?
     
    Martin Dechev, Sep 22, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Ramey
    Replies:
    2
    Views:
    694
    Michael Ramey
    Feb 4, 2004
  2. Replies:
    5
    Views:
    5,600
  3. Ronald
    Replies:
    2
    Views:
    860
    Robbe Morris [C# MVP]
    Jan 17, 2006
  4. Faizan Ahmed
    Replies:
    1
    Views:
    301
    John Saunders
    Jan 4, 2005
  5. Denny Smolinski via .NET 247

    Dynamic Controls, Placeholder, Retrieve Information from Dynamic Controls

    Denny Smolinski via .NET 247, May 4, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    485
    Eidolon
    May 4, 2004
Loading...

Share This Page