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

Unable to get HTML content from one window to another

2 Answers 72 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Huzefa
Top achievements
Rank 1
Huzefa asked on 22 Oct 2008, 10:33 AM
Hi Everyone,

I have taken one Radwindow and have a rad editor displayed in that window.
Now with the help of javascript i taking a reference to the editor and passing the html content from the window to the form.

Here is the javascript in the RadWindow having editor

function saveClicked() 
    { 
        var editor = $find('ReditorGc')//GetRadEditor("ReditorGc"); //get a reference to RadEditor client object 
        var oValue = editor.get_html(false); //get the HTML content 
        oValue = oValue.replace("<","&lt;"); 
        oValue = oValue.replace(">","&gt;");
        var oWindow = GetRadWindow(); 
        var arg = new Object();      
        arg.content = oValue; 
        oWindow.argument = arg; 
        oWindow.Close();         
    } 
    function GetRadWindow() 
    { 
        var oWindow = null
        if (window.radWindow) oWindow = window.radWindow; 
        else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; 
        return oWindow; 
    }  

OnClientClose event of the RadWindow and i taking the value of the Editor and savin in the database.

Code for OnClientClose is below :

sScript.Append("function OnClientClose(radWindow){if(radWindow.argument){alert(radWindow.argument.content);document.getElementById('" + hfPropertyChanged.ClientID + "').value = radWindow.argument.content;__doPostBack('" + hfPropertyChanged.UniqueID + "','');}}"); 
            Telerik.Web.UI.RadScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "OnClientClose", sScript.ToString(), true); 

The problem is :
When i type normal text without any formatting like making it bold,underline etc i am  ABLE to get the value.
But when i add the Bold, underline etc it FAILS with error:

Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occured while processing the request on the server. The status code returned from the server was: 500

I am unable to figure out the problem. What i think is it is not able to parse html tags like "<,>,/" etc thats why its failing to send the content.

Can you please provide a solution or feedback

Thanx.
Huzefa


2 Answers, 1 is accepted

Sort by
0
Serrin
Top achievements
Rank 1
answered on 22 Oct 2008, 08:08 PM
Hi Huzefa,

Generally this problem comes from trying to move un-encoded data around, it doesn't like when you try to move data that has markup tags.  Normally I only encounter this on the server side, so I can use htmlencode/htmldecode to modify the code for safe transmission in my code-behind.

Anyone have any clue how to do this in javascript?  Google isn't being very forthcoming today. ;D
0
Huzefa
Top achievements
Rank 1
answered on 23 Oct 2008, 07:09 AM
Hi,

I am not sure how to use htmlencode/htmldecode on server side though... As stated i was able to do away with this problem by using this :

var oValue = editor.get_html(false); //get the HTML content 
oValue = oValue.replace(/</ig,"&lt;"); 
oValue = oValue.replace(/>/ig,"&gt;"); 

I just replaced all the < with its equivalent &lt; and all the > with its equivalent &gt;

But what now i am facing is when i put content in the label control its not able to recognize the html content. Like when i set the text property of Label to the content returned from editor it dispays as it is
eg Text : Hello and if i bold it then the html would be
<strong>Hello</strong>

This same Text is displayed in the Label as
<STRONG>Hello</STRONG>
which means its not able to recognize the html tags and again when i pass this text to editor I put text value into session variable and pass it to editor
then use this code :

if (Session["Content"] != null
     //Control ctr = (Control)Session["Content"]; 
     ReditorGc.Content = ((Label)Session["Content"]).Text; 

and in the editor the text is displayed as it is like <STRONG>Hello</STRONG>

Why is it not able to recognoze the html tags ?
What should be done to make it right ?

Thank you.
Huzefa
Tags
Editor
Asked by
Huzefa
Top achievements
Rank 1
Answers by
Serrin
Top achievements
Rank 1
Huzefa
Top achievements
Rank 1
Share this question
or