Is there an easier way to make a datalist aware of line breaks within
text fields?
I have a text box that users can type into. If they press the enter key
a few times, VB sees this as a vbCrLf. This text is inserted into a text
field in an SQL server. When the data is read and presented by the
datalist, the line breaks are gone. All the text is just together
without paragraphing.
I am able to keep the spaces if I try this approach:
txtNewLog.Text = Replace(txtNewLog.Text, vbCrLf, "<br />")
That works when the text is shown by the datalist. But when I go to
'edit' that text, the text shows the <br /tags. If the user tries to
post that back, I get this error:
A potentially dangerous Request.Form value was detected from the client
(dlNotes$ctl00$txtEditLog="...m''s Test.<br /><br />A line b...").
This is an understandable security precaution on .Net's part and I don't
wish to turn of this validation.
The other option I tried was to revert things back on the 'EditItem'
procedure (the OnEditCommand="UpdateNote" within the datalist
paramaters) by reversing the replace function, like so:
txtEditLog.Text = Replace(txtEditLog.Text, "<br />", vbCrLf)
The problem with that is when I execute the Edit sub, the control
'txtEditLog' cannot be found using this code within the sub:
Sub EditNote(ByVal sender As Object, ByVal e As DataListCommandEventArgs)
Dim txtEditLog As New TextBox
txtEditLog = e.Item.FindControl("txtEditLog")
txtEditLog.Text = Replace(txtEditLog.Text, "<br />", vbCrLf)
......
End Sub
Controls can be found just fine in the Update Procedure (the
OnUpdateCommand="UpdateNote" within the datalist paramaters). I wasn't
aware until now that controls cannot be declared and found within the
OnEditCommand event procedure.
Any advice on fixing this delimma?
TIA,
Jim