This is a migrated thread and some comments may be shown as answers.

RadEditor in RadGrid Edit Mode "Rewriting" Content

3 Answers 126 Views
Editor
This is a migrated thread and some comments may be shown as answers.
GP
Top achievements
Rank 1
GP asked on 09 Mar 2011, 10:45 PM
I have a weird quirk, and I am trying to figure out how to prevent it.  I have an EditTemplate on my radgrid with a radeditor.  This radeditor seems to be modifying my comments even if I don't actually type anything new.  I'm trying to trap when users don't actually make a comment change, but that trap is being passed over with this quirk.  I am attaching a picture of the differences as they appeared in the VS Text Visualizer.  It shows that though they look very similar, there are some subtle differences, like magic carriage returns.  Again, I am not typing anything new into the content area.  I just click the edit button, then the update button.  There should be no difference.  (But there is)

Here is the code for this:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True"
                        AllowPaging="True" AllowSorting="True" GridLines="None" Skin="WebBlue"
                        OnNeedDataSource="RadGrid1_NeedDataSource"
                        OnDataBound="RadGrid1_DataBound" width="100%"
                        AutoGenerateColumns="False">
                        <ExportSettings  ExportOnlyData="True" IgnorePaging="true" OpenInNewWindow="true">
                            <Excel Format="ExcelML" />
                        </ExportSettings>
                        <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True">
                        </ClientSettings>
                        <MasterTableView CommandItemDisplay="Top" PageSize="10">
                            <CommandItemSettings >
                             </CommandItemSettings>
                            <RowIndicatorColumn>
                                <HeaderStyle Width="20px"></HeaderStyle>
                            </RowIndicatorColumn>
                            <ExpandCollapseColumn>
                                <HeaderStyle Width="20px"></HeaderStyle>
                            </ExpandCollapseColumn>
                            <Columns>
                                <telerik:GridButtonColumn CommandName="Edit" Text="Edit" UniqueName="EditColumn" ButtonType="ImageButton" ></telerik:GridButtonColumn>
                                <telerik:GridBoundColumn DataField="ID" FilterControlWidth="30px"
                                    HeaderText="Comment ID" UniqueName="ID"></telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="CommentDate" FilterControlWidth="30px"
                                    HeaderText="Comment Date" UniqueName="column2">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Commentor" HeaderText="Commentor"
                                    UniqueName="column3">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Comment" HeaderText="Comment"
                                    UniqueName="column4">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="InsertDate" FilterControlWidth="30px"
                                    HeaderText="Insert Date" UniqueName="column5">
                                </telerik:GridBoundColumn>
                            </Columns>
                            <CommandItemTemplate>
                                <a href="#" onclick="return ShowInsertForm();">Add New Comment</a>
                                <asp:ImageButton ID="excelExport" runat="server" ImageUrl="~/images/ExportToExcel.gif" CommandName="ExportToExcel" ImageAlign="Right" />
                            </CommandItemTemplate>
                            <EditFormSettings EditFormType="Template">
                            <EditColumn FilterControlAltText="Filter EditCommandColumn column" UniqueName="editTemplate"></EditColumn>
                                <FormTemplate>
                                    <table id="Table1" cellspacing="1" cellpadding="1" border="0" class="module">
                                        <tr>
                                            <td colspan="2"><strong>Update Comment:</strong>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                ID:
                                            </td>
                                            <td>
                                                <asp:label ID="ID_TextBox" runat="server" Text='<%# Bind("ID") %>'>
                                                </asp:label>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                Comment Date:
                                            </td>
                                            <td>
                                                <telerik:RadDatePicker ID="cmDate" Runat="server" DateInput-EmptyMessage="Select a Date" Skin="WebBlue" SelectedDate='<%# Bind("CommentDate") %>' >
                                                </telerik:RadDatePicker>
                                                <asp:RequiredFieldValidator ID="PickerRequiredFieldValidator" runat="server" Display="Dynamic"
                                                ControlToValidate="cmDate" ErrorMessage="Please select a date" ForeColor="Black" Font-Bold="True" Font-Italic="True" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                Comment:
                                            </td>
                                            <td>
                                                <asp:RequiredFieldValidator ID="TextBoxRequiredFieldValidator" runat="server" Display="Dynamic"
                                                ControlToValidate="txtComment" ErrorMessage="Must Enter Comment" ForeColor="Black" Font-Bold="True" Font-Italic="True" /><br />
                                                <telerik:RadEditor ID="txtComment" runat="server" Skin="WebBlue" EnableResize="False" Width="600px" Height="250px" Content='<%# Bind("Comment")%>'>
                                                    <CssFiles>
                                                        <telerik:EditorCssFile value="~Style/EditorContentArea.css" />
                                                    </CssFiles>
                                                    <Tools>
                                                        <telerik:EditorToolGroup Tag="MainToolbar">
                                                            <telerik:EditorTool Name="FindAndReplace" />
                                                            <telerik:EditorSeparator />
                                                            <telerik:EditorSplitButton Name="Undo">
                                                            </telerik:EditorSplitButton>
                                                            <telerik:EditorSplitButton Name="Redo">
                                                            </telerik:EditorSplitButton>
                                                            <telerik:EditorSeparator />
                                                            <telerik:EditorTool Name="Cut" />
                                                            <telerik:EditorTool Name="Copy" />
                                                            <telerik:EditorTool Name="Paste" ShortCut="CTRL+V" />
                                                        </telerik:EditorToolGroup>
                                                        <telerik:EditorToolGroup Tag="Formatting">
                                                            <telerik:EditorTool Name="Bold" />
                                                            <telerik:EditorTool Name="Italic" />
                                                            <telerik:EditorTool Name="Underline" />
                                                            <telerik:EditorSeparator />
                                                            <telerik:EditorSplitButton Name="ForeColor">
                                                            </telerik:EditorSplitButton>
                                                            <telerik:EditorSplitButton Name="BackColor">
                                                            </telerik:EditorSplitButton>
                                                            <telerik:EditorSeparator />
                                                            <telerik:EditorDropDown Name="FontName">
                                                            </telerik:EditorDropDown>
                                                            <telerik:EditorDropDown Name="RealFontSize">
                                                            </telerik:EditorDropDown>
                                                        </telerik:EditorToolGroup>
                                                    </Tools>
                                                    <Content>
                                                    </Content>
                                                </telerik:RadEditor>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="right" colspan="2">
                                                <asp:Button ID="btnUpdate" Text='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "Insert", "Update") %>'
                                                    runat="server" CommandName='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "PerformInsert", "Update")%>' >
                                                </asp:Button
                                                <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
                                                CommandName="Cancel"></asp:Button>
                                            </td>
                                        </tr>
                                    </table>
                                </FormTemplate>
                            </EditFormSettings>
                        </MasterTableView>
                    </telerik:RadGrid>


Private Sub RadGrid1_UpdateCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand
    'Get User's name
    connSql.ConnectionString = sqlConn.ToString()
 
    Dim exSqlUser As New SqlCommand("dbo.getUser", connSql)
    exSqlUser.CommandType = CommandType.StoredProcedure
    exSqlUser.Parameters.AddWithValue("@UID", user)
    exSqlUser.Parameters.Add("@UserName", SqlDbType.VarChar, 40)
    exSqlUser.Parameters("@UserName").Direction = ParameterDirection.Output
 
    connSql.Open()
    exSqlUser.ExecuteNonQuery()
    connSql.Close()
    Dim username As String = exSqlUser.Parameters("@UserName").Value.ToString()
 
    'get Values and compare
    Dim gridediteditem As GridEditFormItem = CType(e.Item, GridEditFormItem)
    Dim newValues As Hashtable = New Hashtable
 
    e.Item.OwnerTableView.ExtractValuesFromItem(newValues, gridediteditem)
 
    'e.Item.OwnerTableView.ExtractValuesFromItem(oldValues, gridediteditem.SavedOldValues)
    Dim Comment As String, CommentDate As DateTime, Updating As String
    Dim oldComment As String = gridediteditem.SavedOldValues("Comment")
    Dim oldDate As DateTime = gridediteditem.SavedOldValues("CommentDate")
 
    Dim ID As Integer
    If newValues.Item("ID") = Nothing Then
        ID = ""
    Else
        ID = CInt(newValues.Item("ID"))
    End If
 
    Dim newCommentDate As DateTime
    If newValues.Item("CommentDate") = Nothing Then
        newCommentDate = ""
    Else
        newCommentDate = newValues.Item("CommentDate").ToString()
    End If
 
    Dim newComment As String
 
    If newValues.Item("Comment") = Nothing Then
        newComment = ""
    Else
        newComment = newValues.Item("Comment").ToString()
    End If
 
    If oldComment <> newComment And newComment <> "" Then
        Updating = "Yes"
        If oldDate <> newCommentDate Then
            Comment = newComment & "<br />Modified by " & username & " on " & Today().ToString() & "<br />" &
                "Date changed from: " & oldDate & " to: " & newCommentDate & " by " & username & " on " & Today().ToString() & "<br /><br />" & oldComment
            CommentDate = newCommentDate
        Else
            Comment = newComment & "<br />Modified by " & username & " on " & Today().ToString() & oldComment
        End If
    Else
        If oldDate <> newCommentDate Then
            Updating = "Yes"
            CommentDate = newCommentDate
            Comment = "<br /> Date changed from: " & oldDate & " to: " & newCommentDate & " by " & username & " on " & Today().ToString() & "<br /><br />" & oldComment
        End If
    End If
 
    If Updating = "Yes" Then
        Dim exSqlCom As New SqlCommand("dbo.EditComment", connSql)
        exSqlCom.CommandType = CommandType.StoredProcedure
        exSqlCom.Parameters.AddWithValue("@ID", ID)
        exSqlCom.Parameters.AddWithValue("@RapID", RadComboBox1.SelectedValue)
        exSqlCom.Parameters.AddWithValue("@User", user)
        exSqlCom.Parameters.AddWithValue("@CommentDate", CommentDate)
        exSqlCom.Parameters.AddWithValue("@Comment", Comment)
        exSqlCom.Parameters.Add("@ReturnValue", SqlDbType.Int)
        exSqlCom.Parameters("@ReturnValue").Direction = ParameterDirection.Output
 
        connSql.Open()
        exSqlCom.ExecuteNonQuery()
        connSql.Close()
    End If
 
End Sub

3 Answers, 1 is accepted

Sort by
0
GP
Top achievements
Rank 1
answered on 10 Mar 2011, 02:36 PM
This is for all browsers.  I'm trying a workaround, but it's still not quite right.
0
GP
Top achievements
Rank 1
answered on 10 Mar 2011, 03:29 PM
I found another post that better described my issue at hand: http://www.telerik.com/community/forums/aspnet/editor/radeditor-seems-to-insert-carriage-return-and-line-feeds-around-lt-p-gt-and-lt-br-gt-tags.aspx

I tried using the enablehtmlindentation=false method, and I have also tried to trim, and string.replace a lot of stuff, but I am still not catching the bug:
Dim mystring As String
mystring = newComment
mystring = mystring.Replace(" ", "")
mystring = mystring.Replace("<br />", "")
mystring = mystring.Replace(" ", "")
mystring = mystring.Replace("\n\r", "")
mystring = mystring.Replace("\n", "")
mystring = mystring.Replace("\r", "")
mystring = mystring.Replace(Environment.NewLine, String.Empty)
mystring = mystring.Trim()


Any help would be greatly appreciated.

0
GP
Top achievements
Rank 1
answered on 10 Mar 2011, 04:44 PM
I got it to work.  I had to use a string.replace(chr(13), "") and string.replace(chr(10), "") to get the carriage return and line feed out.

Dim mystring As String
mystring = newComment
mystring = mystring.Replace(" ", "")
mystring = mystring.Replace("<br>", "")
mystring = mystring.Replace("<br />", "")
mystring = mystring.Replace(" ", "")
mystring = mystring.Replace(" ", "")
mystring = mystring.Replace(" ", "")
mystring = mystring.Replace(Chr(13), "")
mystring = mystring.Replace(Chr(10), "")
mystring = mystring.Trim()
 
Dim mystring2 As String
mystring2 = oldComment
mystring2 = mystring2.Replace(" ", "")
mystring2 = mystring2.Replace("<br>", "")
mystring2 = mystring2.Replace("<br />", "")
mystring2 = mystring2.Replace(" ", "")
mystring2 = mystring2.Replace(" ", "")
mystring2 = mystring2.Replace(" ", "")
mystring2 = mystring2.Replace(Chr(13), "")
mystring2 = mystring2.Replace(Chr(10), "")
mystring2 = mystring2.Trim()


Tags
Editor
Asked by
GP
Top achievements
Rank 1
Answers by
GP
Top achievements
Rank 1
Share this question
or