programmatically (VB.NET) I am trying to dynamically add results to this screen, and I just want to put the break tag after the la...">

Paste tag <br/"> programmatically (VB.NET)

I am trying to dynamically add results to this screen, and I just want to put the break tag after the label to start placing information on the next line. For some reason, using a literal doesn't work 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) 

This is the part of the code I'm trying to use.


Let me clarify what I said:

It does not work, as in a line break, does not appear on a web page. It compiles fine, and there is nothing wrong with the code. It just doesn't appear in html for some odd reason.

+6
literals
source share
7 answers

The correct control is the HtmlGenericControl .

 Dim br As New HtmlGenericControl("br") 

You can use HtmlGenericControl to render any HTML element that you want, just pass the element tag name as one argument to the constructor.

+14
source share

Why not just use a different label or add <br> to the previous label.txt file?

+2
source share

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

you can try:

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

to see the gap.

But I think you should first add the dummy text to this Literal and find it on your page if it is added. because your code looks fine.

+2
source share


I know this is reviving the old post, but I do not see a clear answer, and I finally figured it out for my own application. Hope this helps someone else!

In my application, I tried to create the control once and add it again wherever I needed. The control will be created only once for each parent.
You need to create a new control every time you need it!
So this is:

 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) 
+2
source share

I'm not sure if the break is a fallback word in vb.net, so try

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

or

 newline.Text="<br>"; 
+1
source share

I would try to execute the code using the debugger to make sure that the line got in, also check three times that divListenerInfo is the right control.

0
source share

I think you are using a panel or placeholder.

vb.net or C # .net syntax:

 divListenerInfo.Controls.Add(New LiteralControl("< br >")) 
0
source share

All Articles