By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,098 Members | 1,881 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,098 IT Pros & Developers. It's quick & easy.

I need some help with this

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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

--
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!)
"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:3D**********************************@microsof t.com...
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

Nov 19 '05 #2

P: n/a
<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.

--
2004 and 2005 Microsoft MVP C#
Robbe Morris
http://www.robbemorris.com
http://www.masterado.net/home/listings.aspx

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:3D**********************************@microsof t.com...
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

Nov 19 '05 #3

P: n/a
That did't work. Any other ideas?

"Robbe Morris [C# MVP]" wrote:
<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.

--
2004 and 2005 Microsoft MVP C#
Robbe Morris
http://www.robbemorris.com
http://www.masterado.net/home/listings.aspx

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:3D**********************************@microsof t.com...
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


Nov 19 '05 #4

P: n/a
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!)
"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:6B**********************************@microsof t.com...
That did't work. Any other ideas?

"Robbe Morris [C# MVP]" wrote:
<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.

--
2004 and 2005 Microsoft MVP C#
Robbe Morris
http://www.robbemorris.com
http://www.masterado.net/home/listings.aspx

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:3D**********************************@microsof t.com...
> 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


Nov 19 '05 #5

P: n/a
Thanks

"Karl Seguin" wrote:
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!)
"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:6B**********************************@microsof t.com...
That did't work. Any other ideas?

"Robbe Morris [C# MVP]" wrote:
<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.

--
2004 and 2005 Microsoft MVP C#
Robbe Morris
http://www.robbemorris.com
http://www.masterado.net/home/listings.aspx

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:3D**********************************@microsof t.com...
> 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


Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.