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

Issue in set_html and $find of radEditor Q2 2008

3 Answers 230 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Vaibhav
Top achievements
Rank 1
Vaibhav asked on 30 Sep 2008, 04:32 AM
I need to set editor's content to some value on page_load from client script.
<body onload="SetButtons();" >
    <form id="form1" runat="server">
....
....

Iin SetButtons :

<script language = "javascript">

function SetButtons ()
{
var editor = <%=radEditContent.ClientID %>;
    var oArg = window.opener.GetCreativeContent();
    editor.SetHtml(oArg);
}

</script>

This works fine with Q3 2007 controls. I can't reproduce this functionalityin Q2 2008 controls.
Issues I am facing are

- var editor = $find("<%=radEditContent.ClientID%>")

in this case editor is null

or
- set_html is not recognized

Some time I get editor but set_html is not working

Can somebody throw some light on it?

3 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 30 Sep 2008, 03:47 PM
Hello Vaibhav,

RadEditor for ASP.NET AJAX is created just as the last code on the page in the Sys.Application.init MS AJAX event, which is raised after the window.onload event. That is why if you put your js code which tries to obtain a reference to RadEditor in the head tag, then the editor will be not yet created and the reference to the editor will return undefined.

This information is available in the following help article: Getting a Reference to RadEditor.

If you experience any problems, please open a support ticket and send a sample working project that demonstrates them. We will examine them and will provide guidance how to solve the issues.

Best regards,
Rumen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Vaibhav
Top achievements
Rank 1
answered on 21 Nov 2008, 07:26 AM
Hi,

I am setting radEditor's content using following code in aspx page.

Issue is when I click on undo button as soon as page is rendered the entire content area is cleared. But if i hardcode content area it is not cleared on undo button.
I expect only that content should be undone which I have typed when page is rendered.

<telerik:RadEditor>
.......
 </telerik:RadEditor>
         <script language="javascript">
                        Sys.Application.add_load
                        (
                            function sethtmlcontent()
                            {
                                var editor1 = $find("<%=radEditContent.ClientID%>");
                                var oArg = GetRadWindow().BrowserWindow.GetCreativeContent();
                                editor1.set_html(oArg);
                                editor1.fire("ToggleScreenMode");                        
                            }
                        );
        </script>

Thanks & Regards,
Vaibhav Gangal
0
Accepted
Rumen
Telerik team
answered on 21 Nov 2008, 12:51 PM
Hello Vaibhav,

When the set_html() method is fired, the operation is added to the Undo list. You should use the innerHTML attribute of the editor's content area to set content in the editor, which will be not listed in the Undo list, e.g.

<script language="javascript">
Sys.Application.add_load
(
    function sethtmlcontent()
    {
        var editor1 = $find("<%=RadEditor1.ClientID%>");
        var oArg = 'test';
        editor1.get_contentArea().innerHTML = oArg;
        editor1.fire("ToggleScreenMode");                       
    }
);
</script>

Regards,
Rumen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Samir
Top achievements
Rank 1
commented on 23 Aug 2022, 08:54 PM

I am working on similar issue but it's on User Control and when i type the above code it gives me HTMLButtonElement.Onclick is not defined.
Rumen
Telerik team
commented on 24 Aug 2022, 07:00 AM

Hi Samir,

Wrap the script inside <telerik:RadCodeBlock>or <telerik:RadScriptBlock> and make sure that the button reference is working.

If you still need assistance, share the aspx, ascx files and their codebehind plus a Fiddler Jam capture.

Samir
Top achievements
Rank 1
commented on 24 Aug 2022, 04:06 PM

<script type="text/javascript" lang="javascript">

var editor = $find(<%=rtxtsourceTitleOverride.Client%>");

editor.get_contentArea().innerHTML("test");

</script>

just a button calling the function on click.

Samir
Top achievements
Rank 1
commented on 24 Aug 2022, 07:43 PM

I have added the <telerik:RadCodeBlock> before the script and also used the closing tag, but still give me same error message.

The button was under Udpate panel which I removed from code but still it does not do anything and gives me the same error message.

We were using CKEditor and the code worked fined but the code was placed on aspx page and not on ascx page. it worked fine and there was option to re-render the CK Editor to refresh.

That code works fine, when i use it with RadEditor but, after the update it make the rad editor disabled and only shows as text or label, guess it doesn't recognize as RadEditor.

 

Samir
Top achievements
Rank 1
commented on 25 Aug 2022, 03:37 AM

I tried to do just get client id for rad editor with a new button and same function that is on website for to alert client id for editor is giving me the same error.  Am I missing something on ascx or ascx.cs page? Ref? or something
Rumen
Telerik team
commented on 25 Aug 2022, 02:22 PM

This line var editor = $find(<%=rtxtsourceTitleOverride.Client%>"); should be var editor = $find(<%=rtxtsourceTitleOverride.ClientID%>");

If this does not work see how the button ID gets resolved in the HTML markup (View Source) when the page is rendered and supply it as an argument to the $find function.

Another useful resource is this blog post on the matter: The difference between ID, ClientID and UniqueID.

If you still experience the issue, please open a support ticket and send a simple working project that shows it. I will examine it and provide a solution.

Samir
Top achievements
Rank 1
commented on 25 Aug 2022, 03:12 PM

I think it was typo on my part as i can't copy paste to editor here.  How do i create support ticket?
Samir
Top achievements
Rank 1
commented on 25 Aug 2022, 07:20 PM

I think the reason it's giving the error is due to it can't find the method  set_HTML, get.contentHTML or even pastHTML that you say it exists for Telerik.
Rumen
Telerik team
commented on 26 Aug 2022, 07:58 AM

The set_html, get_contentArea, pasteHtml methods do not work because the reference to RadEditor is incorrect. That is why I shared a link to The difference between ID, ClientID and UniqueID blog and also wrote how to try to get a properly working reference to the control to be able to use its API.

Nevertheless, for your convenience I created and attached two videos that you can use to see how to:

You can also find different techniques for obtaining a client-side reference to the Telerik controls in this article: Getting Client-Side References to Control Objects.

Samir
Top achievements
Rank 1
commented on 26 Aug 2022, 09:58 PM

No matter what i tried, nothing works for usercontrol.  I can't find any control using javascript.  It can't reconginze the control on aspx page, no matter if i use it's uniqueid or clientid.
Rumen
Telerik team
commented on 29 Aug 2022, 08:54 AM

Please find attached an example showing how to get a reference to control placed in a UserControl from the main aspx page. 

You can find another example in this article Find and access control inside UserControl (ASCX) from Parent Page (ASPX) using JavaScript in ASP.Net

Tags
Editor
Asked by
Vaibhav
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Vaibhav
Top achievements
Rank 1
Share this question
or