CRLF ..

J

Jim in Arizona

When I write code to show the text from a database that was posted from a
textbox, no carriage returns show up. If I load the text back into a text
box, the original carriage returns are there.

The way I'm writing the text to a webpage is via HTML. I use a <div
id="htmltext" runat=server> then do a htmltext.InnerHTML = strResultsHolder.
I don't know how I would tell HTML to insert a <br> or <p> where the
carriage return/line feed should be. I like the control I have when writing
to the page as an HTML stream. Is there a better way?

TIA,
Jim
 
J

Jim in Arizona

Sparky Arbuckle said:
Hey Jim &vbCrlf this is &vbCrlf how!

Looks like:

Hey Jim
this is
how!

I understand the vbCrLf syntax and have used it in VB6 and VB.NET.

My problem has to do with putting the propery paragraphs in HTML from vb.
I'll give you a coding exampe:

------------------------------------------------------------------------

Protected Sub btnTransfer_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnTransfer.Click

Dim strConnection, strSQLTransfer, strSQL, strSQLNote, strResults,
strSQLRemove, txtID As String
Dim objConnection As OleDbConnection
Dim objCommand As OleDbCommand
Dim objDataReader As OleDbDataReader

txtISNotes.Text = Replace(txtISNotes.Text, "'", "''")

txtID = txtTransfer.Text

strResults = ""

strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
"e:\hhsinternal\cterrorlog\ctprob.mdb"

strSQL = "SELECT ID, ClientID, Field, Form, Employee, username," & _
" ip, probdt, Descript, isnotes, noshow FROM TProblem" & _
" WHERE ((TProblem.noshow)= NO) ORDER BY ID DESC;"

strSQLTransfer = "INSERT INTO TClaimTrak (ID, ClientID, Form, Field,
Descript, "
strSQLTransfer += "Employee, username, isnotes) "
strSQLTransfer += "SELECT TProblem.ID, TProblem.ClientID,
TProblem.Form, TProblem.Field, "
strSQLTransfer += "Tproblem.Descript, TProblem.Employee,
Tproblem.username, TProblem.isnotes "
strSQLTransfer += "FROM TProblem "
strSQLTransfer += "WHERE TProblem.ID=" & txtID & ";"

strSQLNote = "UPDATE TProblem"
strSQLNote += " Set isnotes = '" & txtISNotes.Text & "'"
strSQLNote += " WHERE id = " & txtID & ";"

strSQLRemove = "UPDATE TProblem"
strSQLRemove += " Set noshow = True"
strSQLRemove += " WHERE id = " & txtTransfer.Text & ";"


objConnection = New OleDbConnection(strConnection)
objConnection.Open()

If Not txtISNotes.Text = "" Then
objCommand = New OleDbCommand(strSQLNote, objConnection)
objCommand.ExecuteNonQuery()
End If

objCommand = New OleDbCommand(strSQLTransfer, objConnection)
objCommand.ExecuteNonQuery()

objCommand = New OleDbCommand(strSQLRemove, objConnection)
objCommand.ExecuteNonQuery()

objCommand = New OleDbCommand(strSQL, objConnection)
objDataReader = objCommand.ExecuteReader()

Do While objDataReader.Read() = True
strResults += "<table cellpadding=""5"" cellspacing=""0""
border=""1"" bordercolor=""maroon"" width=""90%""><tr>"
strResults += "<td bgcolor=""red"" width=""10%""><b>ID:<br
/><font color=""white"">" & objDataReader("ID").ToString &
"</font></b></td>"
strResults += "<td bgcolor=""silver"" width=""30%""><b>Client
ID:</b><br />" & objDataReader("ClientID").ToString & "</td>"
strResults += "<td bgcolor=""silver""
width=""30%""><b>Field:</b><br />" & objDataReader("Field").ToString &
"</td>"
strResults += "<td bgcolor=""silver""
width=""30%""><b>Form:</b><br />" & objDataReader("Form").ToString & "</td>"

strResults += "</tr><tr>"

strResults += "<td bgcolor=""silver"" width=""10%""><b>Employee
Name:<br /><font color=""navy"">" & objDataReader("Employee").ToString &
"</font></b></td>"
strResults += "<td bgcolor=""silver""
width=""30%""><b>Username:</b><br />" & objDataReader("username").ToString &
"</td>"
strResults += "<td bgcolor=""silver"" width=""30%""><b>IP
Address:</b><br />" & objDataReader("ip").ToString & "</td>"
strResults += "<td bgcolor=""silver""
width=""30%""><b>Date/Time:</b><br />" & objDataReader("probdt").ToString &
"</td>"

strResults += "</tr><tr>"

strResults += "<td colspan=""4""><b>Description:</b><br />" &
objDataReader("Descript").ToString & "</td>"
strResults += "</tr><tr>"
strResults += "<td colspan=""4""><b>HHS Info Systems
Notes:</b><br />" & objDataReader("isnotes").ToString & "<br /></td>"
strResults += "</tr></table>"
strResults += "<br />"
Loop

objDataReader.Close()
objConnection.Close()

report.InnerHtml = strResults
txtTransfer.Text = ""
txtISNotes.Text = ""
End Sub

------------------------------------------------------------------------

I copied and pasted that from one of the pages I'm referring to. What
happens is when someone types into a textbox and clicks the button, that
text is placed into a memo field in an Access database. Then, that note is
redrawn to the browser with HTML. If the person had pressed the ENTER button
a few times and began a new paragraph in the text box, that new paragraph
will not show up when the note is rewritten to the browser. There is only a
single space instead of new blank lines. If they click another button that
loads the note back into a textbox, the text that they typed is in its
original format, with the blank lines. So, it looks like the database is
keeping the original format, but the HTML stream is not writing those extra
lines.

So, how do I get around this?

Thanks,
Jim
 
K

Kevin Spencer

Dim s As String = "some string with line breaks in it"

txtISNotes.Text = s.Replace(VbCrLf, "<br>")

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Paranoia is just a state of mind.
 
J

Jim in Arizona

Kevin Spencer said:
Dim s As String = "some string with line breaks in it"

txtISNotes.Text = s.Replace(VbCrLf, "<br>")

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Paranoia is just a state of mind.

Excellent!! Thanks Kevin!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top