Skip to content Skip to sidebar Skip to footer

Asp.net Replacing Line Break With Html Br Not Working

Hi I am trying to submit some information into a database using an ASP.NET multiline textbox. I have the following code: Dim noteContent As String = Replace(txtNoteContent.InnerTex

Solution 1:

When you do your replace, you should check for VbCrLf (Windows Line Break), VbLf (Unix Line Break) and VbCr (Mac Line Break). If memory serves correct, the standard newline in a HTML textarea element is "\n" (aka VbLf), so you might just get away with replacing VbCrLf with VbLf in your code, but personally I always check for them all just to be safe.

Example

Dim htmlBreakElement AsString = "<br />"Dim noteContent AsString = txtNoteContent.Text _
    .Replace(vbCrLf, htmlBreakElement) _
    .Replace(vbLf, htmlBreakElement) _
    .Replace(vbCr, htmlBreakElement)
Shop.Job.Notes.addNote(Request.QueryString("JobID"), ddlNoteFrom.SelectedValue, ddlNoteTo.SelectedValue, noteContent)

Post a Comment for "Asp.net Replacing Line Break With Html Br Not Working"