datalist vbCrLf & OnEditCommand/OnUpdateCommand Event Procedures

Discussion in 'ASP .Net' started by Jim in Arizona, Dec 28, 2006.

  1. 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
     
    Jim in Arizona, Dec 28, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George Durzi

    OnEditCommand - .FindControl Returning Null

    George Durzi, Jul 14, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    505
    George Durzi
    Jul 14, 2003
  2. =?Utf-8?B?S2FyaW5lIFByb290?=

    DataGrid : dynamic BoundColumn & OnUpdateCommand

    =?Utf-8?B?S2FyaW5lIFByb290?=, Jan 27, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,424
    =?Utf-8?B?S2FyaW5lIFByb290?=
    Jan 27, 2004
  3. DC
    Replies:
    2
    Views:
    628
  4. Dan

    DataGrid: OnUpdateCommand - getting the updated values

    Dan, Aug 18, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    172
  5. Jim in Arizona

    datalist vbCrLf & OnEditCommand/OnUpdateCommand Event Procedures

    Jim in Arizona, Dec 29, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    662
    Jim in Arizona
    Dec 29, 2006
Loading...

Share This Page