Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Rendering child controls "inline"

Thread Tools

Rendering child controls "inline"

Posts: n/a

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

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


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


MyBase.ChildControlsCreated = True

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
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
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="" %>
<asp:repeater id="rptBeginElements" runat="server">
<li><%# Container.DataItem %></li>

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

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

<li>Begin Element 1</li>
<li>Begin Element 2</li>
<li>Begin Element 3</li>
<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>
<li>End Element 1</li>
<li>End Element 2</li>
<li>End Element 3</li>

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 ? =)

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
HELP! Child controls of child controls not visible to web app ASP .Net Building Controls 0 05-05-2005 09:14 PM
Mixing child properties and child controls - how? Donal McWeeney ASP .Net Web Controls 3 02-14-2005 02:51 AM
Problem rendering child controls when creating a custom control library Scott Yenor ASP .Net 0 01-22-2004 09:16 PM
How do I: Main thread spawn child threads, which child processes...control those child processes? Jeff Rodriguez C Programming 23 12-09-2003 11:06 PM
rendering child controls in designer johnny ASP .Net Building Controls 1 08-30-2003 12:28 AM