Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > datalist vbCrLf & OnEditCommand/OnUpdateCommand Event Procedures

Thread Tools

datalist vbCrLf & OnEditCommand/OnUpdateCommand Event Procedures

Jim in Arizona
Posts: n/a
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?

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
datalist vbCrLf & OnEditCommand/OnUpdateCommand Event Procedures Jim in Arizona ASP .Net Datagrid Control 0 12-29-2006 10:31 PM
Re: Simple question about 'vbCrLf' is not declared GrantMagic ASP .Net 0 09-21-2004 04:32 PM
Re: Simple question about 'vbCrLf' is not declared Hermit Dave ASP .Net 0 09-21-2004 04:30 PM
Setting up a datalist control - Item_DataBound for a datalist in a datalist Nevyn Twyll ASP .Net 8 09-09-2004 10:13 PM
Click event in a datalist to post back datalist properties Steve Lloyd ASP .Net 1 05-26-2004 04:07 AM