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:
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 IfEnd Sub