New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

Editor Content Is Not Saved After AJAX Update

This help article describes an issue with the content saving of RadEditor after an AJAX update and offers a resolution.

  1. Scenario Description - RadEditor Content is Not Saved After an AJAX Request
  2. Resolutions

Scenario Description - RadEditor Content is Not Saved After an AJAX Request

The RadEditor content is not saved after an AJAX update when one of the following criteria is met:

  • An asp:ImageButton or RadButton updates RadEditor within an asp:UpdatePanel or through RadAjaxPanel/RadAjaxManager (Example 1).

  • An asp:Button updates RadEditor within an asp:UpdatePanel (Example 2).

The unexpected behavior stems from an issue inside the MS AJAX framework that relates to passing information about the partial page update. Considering the fact that RadEditor and RadAjax are built on top of the MS AJAX framework, the controls are also affected by this issue.

In the case of ImageButtons and server buttons, by the time the MS AJAX framework "informs" the editor that a partial update is about to occur, the POST data has already been collected and recorded. The editor does not get a chance to set the updated content properly.

Example 1: An ImageButton updates a RadEditor within a RadAjaxPanel, which causes the editor content to be lost.

ASP.NET
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
	<asp:ImageButton ID="ImageButton1" runat="server" OnClick="btnSave_Click" ImageUrl="https://demos.telerik.com/aspnet-ajax/button/images/images/button.png" />
	<telerik:RadEditor RenderMode="Lightweight" ID="RadEditor1" runat="server"></telerik:RadEditor>
</telerik:RadAjaxPanel>

Example 2: A Button updates a RadEditor within an asp:UpdatePanel, which causes the editor content to be lost.

ASP.NET
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
	<ContentTemplate>
		<asp:Button ID="Button1" runat="server" OnClick="btnSave_Click" Text="Save" />
		<telerik:RadEditor RenderMode="Lightweight" ID="RadEditor1" runat="server"></telerik:RadEditor>
	</ContentTemplate>
</asp:UpdatePanel>

Resolutions

In order to handle the issue you can use one of the following approaches:

telerik:RadButton initiates the request

Set the UseSubmitBehavior property of the push button to false when:

  • A RadButton updates a RadEditor within an asp:UpdatePanel or through RadAjaxPanel/RadAjaxManager.

  • An asp:Button updates a RadEditor within an asp:UpdatePanel (Example 3).

Example 3: A Button with the UseSubmitBehavior property set to false which enables the editor content to be sent to the server.

ASP.NET
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
	<ContentTemplate>
		<asp:Button ID="Button1" runat="server" OnClick="btnSave_Click" UseSubmitBehavior="false" Text="Save" />
		<telerik:RadEditor RenderMode="Lightweight" ID="RadEditor1" runat="server"></telerik:RadEditor>
	</ContentTemplate>
</asp:UpdatePanel>

telerik:RadCheckBox initiates the request

Use the RadCheckBox control events to prevent the default postback in order to initiate it via the standard __doPostBack() method. You also need to use the control API to change its checked state. See Example 4.

Example 4: A RadCheckBox updates the editor without loss of content.

ASP.NET
<asp:UpdatePanel ID="Updatepanel1" runat="server">
	<ContentTemplate>
		<telerik:RadCheckBox runat="server" ID="RadCheckBox1" Text="check me" OnClientClicking="OnClientClicking" AutoPostBack="true" OnCheckedChanged="RadCheckBox1_CheckedChanged"></telerik:RadCheckBox>
		<telerik:RadEditor RenderMode="Lightweight" ID="RadEditor1" runat="server"></telerik:RadEditor>
	</ContentTemplate>
</asp:UpdatePanel>
<script type="text/javascript">
	function OnClientClicking(sender, args) {
		args.set_cancel(true); //prevent the framework postback
		sender.set_checked(!sender.get_checked()); //toggle the checked state because cancelling the event cancels the state change as well
		__doPostBack(sender.get_element().getAttribute("name"), ''); //initiate a postback
	}
</script>

asp:Button initiates the request

Use RadAjaxPanel/RadAjaxManager with asp:Button because they automatically set the UseSubmitBehavior property to false for all asp push buttons (Example 4).

Example 5: Editor content is properly saved after partial update with RadAjaxPanel triggered by а Button.

ASP.NET
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
	<asp:Button ID="Button2" runat="server" OnClick="btnSave_Click" Text="Save" />
	<telerik:RadEditor RenderMode="Lightweight" ID="RadEditor1" runat="server"></telerik:RadEditor>
</telerik:RadAjaxPanel>

asp:ImageButton initiates the request

Use the MS AJAX framework's __doPostBack() method inside the client-side event of the ImageButton because it doesn't have a UseSubmitBehavior property (Example 6).

Example 6: Triggering partial page update by calling the __doPostBack method inside the client click method of an asp:ImageButton, which allows the editor content to be sent to the server.

ASP.NET
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
	<asp:ImageButton ID="ImageButton1" runat="server" OnClientClick="javascript:__doPostBack(this.name,'');return false;" OnClick="btnSave_Click" ImageUrl="https://demos.telerik.com/aspnet-ajax/button/images/images/button.png" />
	<telerik:RadEditor RenderMode="Lightweight" ID="RadEditor1" runat="server"></telerik:RadEditor>
</telerik:RadAjaxPanel>

When RadEditor and an ImageButton are used to update RadGrid fields, you can use the approach from Example 5. You should, however, properly reference the ImageButton from the code behind and handle its onclick event in order to call the __doPostBack() method (Example 7).

Example 7: Calling the __doPostBack() method when image update button in RadGrid is clicked.

ASP.NET
<asp:UpdatePanel ID="Updatepanel2" runat="server">
	<ContentTemplate>
		<telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCreated="RadGrid1_ItemCreated" OnItemCommand="RadGrid1_ItemCommand">
			<MasterTableView AutoGenerateColumns="false" EditMode="InPlace">
				<Columns>
					<telerik:GridEditCommandColumn ButtonType="ImageButton" HeaderText="Edit" UniqueName="EditButton">
					</telerik:GridEditCommandColumn>
					<telerik:GridBoundColumn DataField="ID" HeaderText="ID"></telerik:GridBoundColumn>
					<telerik:GridHTMLEditorColumn DataField="Text" HeaderText="Content" UniqueName="myGridHTMLEditorColumn"></telerik:GridHTMLEditorColumn>
				</Columns>
			</MasterTableView>
		</telerik:RadGrid>
		GridHTMLEditorColumn value after Edit:
		<asp:Label ID="Label1" Text="" runat="server" />
	</ContentTemplate>
</asp:UpdatePanel>

See Also