Search code examples
asp.netpostwebformstelerikradeditor

Telerik RadEditor HTTP POST VALUE not being updated (ASP.NET Web Forms)


I am currently writing a ContentManager in ASP.NET. I have a preview button which uses jQuery to post the form data to new window and shows how a page would look without saving it to the database and effecting the live site. Although its been somewhat of a hassle to get ASP.NET to post directly to the page I am trying to preview, I've finally worked it all out using a series of jQuery code. It worked beautifully, I loaded all the post values into the page using Request.Form and displayed them on the page. Unfortunately for some reason the Telerik RadEditor's I was using were posting me the values they had been assigned on the C# Page_Load event and did not reflect the text changes I made. If anyone could help me out that would be great.

function showPreview()
{
    url = "<%= (SiteManager.GetSite()).Url  + this.Filename %>?preview=true"; 
    var specs = "width=1010,height=700,location=0,resizeable=1,status=1,scrollbars=1"; 
    window.open(url, 'PagePreview', specs).moveTo(25, 25);
    $("#__VIEWSTATE").remove();
    $("#__EVENTTARGET").remove();
    $("#__EVENTARGUMENT").remove();
    $("#aspnetForm").removeAttr("action");
    $("#aspnetForm").attr("target","PagePreview");
    $("#aspnetForm").attr("action", url);
    $("#aspnetForm").submit(); 
}

Here is all the post data I am receiving from the tererik RADEDITOR ::

[ctl00_MainContentPlaceHolder_SideContentRadEditor_dialogOpener_Window_ClientState] => [ctl00_MainContentPlaceHolder_SideContentRadEditor_dialogOpener_ClientState] => [ctl00$MainContentPlaceHolder$SideContentRadEditor] => [ctl00_MainContentPlaceHolder_SideContentRadEditor_ClientState] => [ctl00_MainContentPlaceHolder_ContentRadEditor_dialogOpener_Window_ClientState] => [ctl00_MainContentPlaceHolder_ContentRadEditor_dialogOpener_ClientState] => [ctl00$MainContentPlaceHolder$ContentRadEditor] => %3cp%3eTestPageContent%3c/p%3e 

This is the html value of the text editor (shown above) %3cp%3eTestPageContent%3c/p%3e This is the value in the RadEditor that was loaded during the Page_Load event.

I changed the value to "Test". But it was not sent over the POST Request, it sent what was loaded in the page load.


Solution

  • The editor content area is separate from the textarea used to submit the content during a POST request. The editor will automatically try to save the content in the hidden textarea when the form is submitted, but in your case no event is fired because it happens programmatically (i.e. you call .submit()). You will need to tell the editor to save its content manually before you do the postback. The code is pretty basic - get a reference to the editor and call .saveContent():

    //Grab a reference to the editor
    var editor = $find("<%=theEditor.ClientID%>");
    
    //Store the content in the hidden textarea so it can be posted to the server
    editor.saveContent();