Print Page | Close Window

Generating a label collection

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=21515
Printed Date: 29 March 2026 at 4:24am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Generating a label collection
Posted By: theSCIENTIST
Subject: Generating a label collection
Date Posted: 08 October 2006 at 6:06am
Hi guys
 
I'm generating a collection of labels so it reports each status message in its own <span>...</span> line, like this:
 
<%@ Page Language="VB" Debug="true" %>
<Script Runat="Server">
    Sub Page_Load(o as Object, e as EventArgs)
        Call DoThis()
        Call DoThat()
    End Sub
    Sub DoThis()
        Dim lblStatus As New Label()
        lblStatus.CssClass = "black"
        lblStatus.Text = "This should be black.<br />"
        plcHolder.Controls.Add(lblStatus)
    End Sub
    Sub DoThat()
        Dim lblStatus As New Label()
        lblStatus.CssClass = "red"
        lblStatus.Text = "This should be red.<br />"
        plcHolder.Controls.Add(lblStatus)
    End Sub
</Script>
 
<html>
<head>
  <title>aTitle</title>
  <style>
    body   { font-family: Verdana; }
    .black { color: black; }
    .red   { color: red; }
  </style>
</head>
<body>
<asp:PlaceHolder ID="plcHolder" runat="server" />
</body>
</html>
 
However, the response gives me 2 spans in the same line:
 
<span class="black">This should be black.<br /></span><span class="red">This should be red.<br /></span>
 
I want the spans in seperate lines so I can read what is being generated, I would like it like this:
 
<span class="black">This should be black.<br /></span>
<span class="red">This should be red.<br /></span>
 
I manage to add a vbCrLf like this [ lblStatus.Text = "This should be red.<br />" & vbCrLf ] to both lines but the closer I get is this:
 
<span class="black">This should be black.<br />
</span><span class="red">This should be red.<br />
</span>
 
Now, how do I get this <spans> to output the way I want?
 
By the way, whats the control that will output <divs>?
 
Thanks guys.


-------------
:: http://www.mylittlehost.com/ - www.mylittlehost.com



Replies:
Posted By: MortiOli
Date Posted: 08 October 2006 at 9:24am

Would putting a line break (in the correct format), after plcHolder.Controls.Add(lblStatus) do the trick?

I take it that that's what closes the <span>, so anything after them should work?


Posted By: Mart
Date Posted: 08 October 2006 at 11:54am
Private LineBreak As New LiteralControl()

then in Page_Load...

LineBreak.Text = "<br/>"

then after adding a label to the placeholder

placeholder.Controls.Add(linebreak)


(I didn't test this, but the principle is the same, you need to construct a literal control with <br/> as the text and add it to the placeholder after)


Posted By: theSCIENTIST
Date Posted: 09 October 2006 at 12:29am

The LineBreak.Text should be vbCrLf like; LineBreak.Text = vbCrLf this would output a break after the span is closed. I knew about the Literal control, quite handy as it doesn't output any tag, great.

 
Thanks guys.


-------------
:: http://www.mylittlehost.com/ - www.mylittlehost.com



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net