Question

I'm trying to dynamically add results to this display and I simply want to put a break tag after a label to start putting information on the next line. For some reason, Using a literal isn't working for me. Is there a better way to do this or should I just use tables?

Dim break As LiteralControl
break = New LiteralControl("<br />")
divListenerInfo.Controls.Add(break)

That's part of the code that I'm attempting to use.


Let me clarify what I said:

It's not working as in the line break isn't showing up on the webpage. It's compiling fine and there is nothing wrong with the code. It just doesn't show up in the html for some odd reason.

Was it helpful?

Solution

The proper control to use is the HtmlGenericControl.

Dim br As New HtmlGenericControl("br")

You can use the HtmlGenericControl to render any HTML element you wish, simply pass the element's tag name as a single argument to the constructor.

OTHER TIPS

Why not just use another label, or append the <br> to the previous label.txt?

If the added
is the last element in the container div, you can not see any difference.

you can try :

Dim breakTag As LiteralControl
breakTag= New LiteralControl("<br />&nbsp;")
divListenerInfo.Controls.Add(breakTag)

to see the break.

But I think you should first add a dummy text into this Literal and search for it in your page if it's added. because your code looks fine.


I know this is reviving an old post but I didn't see any clear answer and I finally figured it out for my own application. Hope it helps someone else!
In my application I tried to create the control once and add it again wherever I needed it. The control would only be created once per parent.
You need to create a new control every time you need it!
So this:

divListenerInfo.Controls.Add(New LiteralControl("&lt;br />"))
divListenerInfo.Controls.Add(New LiteralControl("&lt;br />"))

Instead of this

Dim breakTag As LiteralControl
breakTag= New LiteralControl("&lt;br />")
divListenerInfo.Controls.Add(breakTag)
divListenerInfo.Controls.Add(breakTag)

I'm not sure if break is a reserve word also in vb.net so try

Dim newline = New LiteralControl("<br>")

or

newline.Text="<br>"; 

I would try stepping through the code with a debugger to make sure the line gets hit, also triple-check that divListenerInfo is the right control.

I think you are using a panel or placeholder.

vb.net or C# .net syntax:

divListenerInfo.Controls.Add(New LiteralControl("< br >"))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top