views:

1754

answers:

6

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.

+2  A: 

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

madcolor
It works. Thanks
Paxenos
Voted Andrew +1, as I believe he has a cleaner more appropriate solution.
madcolor
+1  A: 

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>";
TStamper
I changed the variable name to make sure, and it didnt change anything.
Paxenos
updated with new solution
TStamper
A: 

what kind of error are you getting?

the literal may be htmlencoding the text you're putting in there.

MasterMax1313
+3  A: 

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.

Andrew Hare
Cool! Was not aware of the HtmlGenericControl previously. Thx.
Cyberherbalist
This isn't working either. The break tag appear nowhere in the html.
Paxenos
It sounds like any new controls you create are not being added to the ControlCollection of the Page itself. You ought to verify that the control itself is actually being added.
Andrew Hare
Only 2 of the 10 "br" controls are being added. I step through and it hits all 10 of them. Any ideas as to why they aren't being shown in the actual html?
Paxenos
It is hard to say without seeing more code - that does sounds really strange though.
Andrew Hare
HtmlGenericControl("br") will render as <br></br>LiteralControl("<br />") is what you want to use. If it's not rendering, there is an issue somewhere else in your code.
Alex Czarto
+1  A: 

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.

Canavar
I put some generic text in the LiteralControl and it only shows up 2 of 10 times in the html. Any clue as to why that is? I stepped through it and the line of code is getting hit, but nothing results of it.
Paxenos
A: 

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.

Alex