468,549 Members | 2,344 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,549 developers. It's quick & easy.

datalist vbCrLf & OnEditCommand/OnUpdateCommand Event Procedures

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
Dec 28 '06 #1
0 1261

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Dude | last post: by
10 posts views Thread by Bharat | last post: by
4 posts views Thread by tshad | last post: by
1 post views Thread by Neil Jarman | last post: by
3 posts views Thread by Crazy Cat | last post: by
1 post views Thread by UniDue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.