K. Weber
K. Weber

Reputation: 2773

Render PlaceHolder within li tags

I've got the next situation: within an ITemplate object I'm rendering a Repeater with <li> elements inside, normally it's done like this:

Dim literalControl as new LiteralControl
literalControl = "<li>blah blah</li>"
container.Controls.Add(literalControl)

But at one point I need to add a PlaceHolder returned by another function which serves other purposes, not only this repeater and I get something like this:

Dim literalControl as new LiteralControl
Dim plTable As PlaceHolder

literalControl = "<li>blah blah</li>"
MyObject.Render(AComplexObect, plTable)

container.Controls.Add(literalControl)
container.Controls.Add(plTable)

This works just fine but elements in placehoder stay outside <li> tag, I want it inside. plTable has many elements of different types inside, so I loop converting it's content to Literal or LiteralControl throws error as not all elements can be converted to these types.

What alternatives do I have?

Thank you

Upvotes: 1

Views: 265

Answers (1)

Irving
Irving

Reputation: 1267

Does this work for you:

Dim literalControl As New LiteralControl
Dim plTable As PlaceHolder
Dim swWriter As New StringWriter
Dim htwWriter As New HtmlTextWriter(swWriter)

MyObject.Render(AComplexObect, plTable)
MyObject.RenderControl(htwWriter)

literalControl.Text = "<li>" & swWriter.ToString() & "</li>"

container.Controls.Add(literalControl)

Upvotes: 1

Related Questions