Rendering child controls "inline"

Discussion in 'ASP .Net Building Controls' started by Netveloper, Dec 1, 2005.

  1. Netveloper

    Netveloper Guest

    Hi,

    I'm currently creating a very basic UserControl. The control implements an
    interface called IAdvanceView which looks like below


    Public Interface IAdvancedView

    Sub OnRenderBegin()

    Sub OnRenderEnd()

    End Interface


    so the idea is to do some tigger some rendering from the control in various
    stages of it's life cycle. The controll collection can contain
    more of my control, so they can be nested. The control overrides the Render
    method

    Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)

    Me.OnRenderBegin()

    For Each SubControl As Control In Me.Controls
    If (TypeOf (SubControl) Is IAdvancedView) Then
    SubControl.RenderControl(writer)
    End If
    Next

    Me.OnRenderEnd()

    MyBase.ChildControlsCreated = True
    MyBase.Render(writer)

    End Sub



    So the concept is

    (1) Call OnRenderBegin on the control - having it do some action, like
    databind a repeater
    (2) Find the next control and have it render, using the same three steps
    (3) Same as (1) but for OnRenderEnd method

    The OnRenderBegin and OnRenderEnd methods are very simple


    Public Sub OnRenderBegin() Implements IAdvancedView.OnRenderBegin

    Dim BeginElements As New ArrayList

    With BeginElements
    .Add("Begin element 1")
    .Add("Begin element 2")
    .Add("Begin element 3")
    End With

    With Me.rptBeginElements
    .DataSource = BeginElements
    .DataBind()
    End With

    End Sub

    Public Sub OnRenderEnd() Implements IAdvancedView.OnRenderEnd

    Dim EndElements As New ArrayList

    With EndElements
    .Add("End element 1")
    .Add("End element 2")
    .Add("End element 3")
    End With

    With Me.rptEndElements
    .DataSource = EndElements
    .DataBind()
    End With

    End Sub

    The HTML code for the contol is equaly simple

    <%@ Control Language="vb" AutoEventWireup="false"
    Codebehind="ContainerView.ascx.vb" Inherits="MyProject.ContainerView"
    TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
    <asp:repeater id="rptBeginElements" runat="server">
    <headertemplate>
    <ul>
    </headertemplate>
    <itemtemplate>
    <li><%# Container.DataItem %></li>
    </itemtemplate>
    </asp:repeater>

    <asp:repeater id="rptEndElements" runat="server">
    <itemtemplate>
    <li><%# Container.DataItem %></li>
    </itemtemplate>
    <footertemplate>
    </ul>
    </footertemplate>
    </asp:repeater>

    So taking the test code, the idea is to have it render list items from the
    data bound to the control in OnRenderBegin and OnRenderEnd and inbetween the
    two, the child controls s hould be created, ineffect creating sublists for
    the child controls. For example if I hade two controls, one located in the
    others Control collection I would like for it to render like

    <ul>
    <li>Begin Element 1</li>
    <li>Begin Element 2</li>
    <li>Begin Element 3</li>
    <ul>
    <li>Begin Element 1</li>
    <li>Begin Element 2</li>
    <li>Begin Element 3</li>
    <li>End Element 1</li>
    <li>End Element 2</li>
    <li>End Element 3</li>
    </ul>
    <li>End Element 1</li>
    <li>End Element 2</li>
    <li>End Element 3</li>
    </ul>

    Now the lists is just a test.. I could ofcourse place other code in my
    repeaters, but I think this illustrates what I want to happen. Now this is
    not the result I'm getting, I keep getting the lists rendered after
    eachother and the second one is rendered twice. The full code is a class



    Public Class ContainerView
    Inherits System.Web.UI.UserControl
    Implements IAdvancedView

    // Insert previous methods here



    End Class



    To test it, create two objects of the control, c1 and c2 .. .add c2 to the
    controls collection of c1 and add c1 to the control collection of a webform.

    Any ideas what I should change ? =)
     
    Netveloper, Dec 1, 2005
    #1
    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. Scott Yenor
    Replies:
    0
    Views:
    384
    Scott Yenor
    Jan 22, 2004
  2. Jeff Rodriguez
    Replies:
    23
    Views:
    1,141
    David Schwartz
    Dec 9, 2003
  3. johnny

    rendering child controls in designer

    johnny, Aug 29, 2003, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    113
    johnny
    Aug 30, 2003
  4. Replies:
    0
    Views:
    209
  5. Donal McWeeney

    Mixing child properties and child controls - how?

    Donal McWeeney, Feb 10, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    127
    [MSFT]
    Feb 14, 2005
Loading...

Share This Page