Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Generating a label collection
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Generating a label collection

 Post Reply Post Reply
Author
theSCIENTIST View Drop Down
Senior Member
Senior Member


Joined: 31 July 2003
Location: United Kingdom
Status: Offline
Points: 440
Post Options Post Options   Thanks (0) Thanks(0)   Quote theSCIENTIST Quote  Post ReplyReply Direct Link To This Post Topic: Generating a label collection
    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.
Back to Top
MortiOli View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 May 2002
Location: United Kingdom
Status: Offline
Points: 514
Post Options Post Options   Thanks (0) Thanks(0)   Quote MortiOli Quote  Post ReplyReply Direct Link To This Post 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?
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post 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)
Back to Top
theSCIENTIST View Drop Down
Senior Member
Senior Member


Joined: 31 July 2003
Location: United Kingdom
Status: Offline
Points: 440
Post Options Post Options   Thanks (0) Thanks(0)   Quote theSCIENTIST Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.