<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
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.
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
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.
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.
<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.
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.
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.
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:
- Obtain a reference to RadEditor and use its API using as a base the Telerik Live demos
- Submit a new support ticket from your account after logging into https://www.telerik.com/account/support-center/contact-us.
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.
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.