I need some help with this

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
What is wrong with this code? I can't figure this out. Its suppose to display

..a bunch
..of errors

on my page. I am stuck for over 4 hrs now an this crap. Please assist.

This is on form load

Dim str As String = "a bunch|of errors"
Dim errors() As String = str.Split("|")
Dim sb As StringBuilder = New StringBuilder

' HTML code for a bulleted list
sb.Append("<ul>\n")

' Append each error to the bulleted list
Dim serror As String

For Each serror In errors
sb.Append("<li>" + serror + "</li>\n")
Next

sb.Append("</ul>")

' Create a <div> tag using an HtmlGenericControl
Dim gc As HtmlGenericControl = New HtmlGenericControl("div")
gc.Attributes.Add("id", "errorList")

' Set its InnerHtml to the error list.
gc.InnerHtml = sb.ToString()

' Add it to the PlaceHolder on the page.
placehandler.Controls.Add(gc)


Thanks
 
The only problem I see is that \n gets outputted. instead try using
System.Environment.NewLine, ala:

sb.Append("<ul>")
sb.Append(System.Environment.NewLine)

....

For Each serror In errors
sb.Append("<li>" + serror + "</li>")
sb.Append(System.Environment.NewLine)
Next


otherwise everything seems fine...

You might consider using a repeater for this type of stuff...

Karl
 
<BR> is the recognized newline tag in HTML. \n will show
in how the code looks in Page Source but will not be
reflected in how the html looks to the user.
 
you weren't very clear, to me atleast, what exactly is wrong. I figured you
wanted to use \n to display a new line in the view source (hence why I
suggested Environment.NewLine). Since you are wrapping your strings in list
items, they'll automatically appear on a new line. If you need extra
spacing between listitems, you should use css...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
 
Thanks

Karl Seguin said:
you weren't very clear, to me atleast, what exactly is wrong. I figured you
wanted to use \n to display a new line in the view source (hence why I
suggested Environment.NewLine). Since you are wrapping your strings in list
items, they'll automatically appear on a new line. If you need extra
spacing between listitems, you should use css...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
 
Back
Top