How to Change default setting for ACT HTML Editor? I want to load editor with for example Selected Bold Button or with rtl direction instead of ltr defaultly.
How can I perform that?
I overrided FillTopToolbar()
method to add Custom buttons but I dont Know how to change default settings.
as Default ltr is selected I want to change it to rtl.
views:
2064answers:
3You will need to do this using CSS as the editor control doesn't support rtl natively. The following CSS will set direction to rtl -
div
{
direction:rtl;
}
The default styles for the HTML editor can be found in the Editor.css file.
I edited my answer to correct some things
The HTMLEditor doesn't provide a way to set the state of those buttons using serverside code. Although, on the client, it initializes by using Sys.Application.load Event. If you ran your code after their initializers, but before the user will interact with the UI, you could then set whatever properties you want to set in that event handler.
Here is the code you need to set the bold button and the rtl buttons states. You can take it from here if you want to change the states of other buttons:
// Attach a handler to the load event.
Sys.Application.add_load(myOnLoadLoader);
function myOnLoadLoader() {
//This will run JUST after ALL code that was set to run during the load event has run
window.setTimeout(myOnLoad, 0);
}
function myOnLoad() {
var editor = $find('<% =editor.ClientID %>');
var toolbar = editor.get_changingToolbar();
var toolbarButtons = toolbar.get_buttons();
for (var i = 0; i < toolbarButtons.length; i++) {
var toolbarButton = toolbarButtons[i];
if (toolbarButton instanceof AjaxControlToolkit.HTMLEditor.ToolbarButton.Rtl ||
toolbarButton instanceof AjaxControlToolkit.HTMLEditor.ToolbarButton.Bold) {
toolbarButton.set_activeEditPanel(editor.get_editPanel());
toolbarButton.callMethod();
}
}
}
Sys (and therefore Sys.Application) is a namespace that comes from the ASP.Net AJAX javascript (file(s) that are added thanks to the ScriptManager that you add to your page). If you use this, you need to be sure that this line Sys.Application.add_load(myOnLoad);
runs after the ASP.Net AJAX files load. You can do this a couple of ways:
- Add this script lower in the page than the scriptManager.
- Move your script into a separate JS file, and use the ScriptManager to load it (recommended).
If you move your script into a separate file, you'll notice that var editor = $find('<% =youreditor.ClientID %>');
no longer works. That is because javascript files do not parse out server tags and replace them with the server side value (as aspx pages do). So the part that is a problem here is <% =youreditor.ClientID %>
.
To fix that, here is what you do:
Add this to your aspx markup (in the head section):
<script language="javascript">
var myEditorId = '<%= youreditor.ClientID %>';
</script>
So it looks something like this:
<head runat="server">
<script language="javascript">
var myEditorId = '<%= youreditor.ClientID %>';
</script>
<title></title>
</head>
(If you are using a Master Page, you'll just add the script tag below the ScriptManager in your page)
And in your JS file, replace this
var editor = $find('<% =youreditor.ClientID %>');
with this
var editor = $find(myEditorId);
This is exactly what I want, but I can't seem to get it working at all. Can anyone help on this? Pretty sure I followed the instructions exactly, and my code looks like this
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<script language= "javascript" type="text/javascript">
// Attach a handler to the load event.
Sys.Application.add_load(myFunction);
function myFunction() {
//Setup myOnLoad to run AFTER the load event handlers have all completed
window.setTimeout(myOnLoad, 0);
}
function myOnLoad() {
//Find the instance of editor
var editor = $find('<%=editor.ClientID %>');
//Access the editor's toolbar
var toolbar = editor.get_changingToolbar();
//Get an array of toolbar buttons
var toolbarButtons = toolbar.get_buttons();
//Loop through the buttons array looking for the one we need
for (var i = 0; i < toolbarButtons.length; i++) {
//If this button is the right to left direction button, then toggle
if (toolbarButtons[i] instanceof AjaxControlToolkit.HTMLEditor.ToolbarButton.Bold) {
//first, make sure the button has an edit panel set
toolbarButtons[i].set_activeEditPanel(editor.get_editPanel());
//Call the callMethod function (toggles the button)
toolbarButtons[i].callMethod();
//toolbarButtons[i].style.display = "none";
}
}
}
</script>
<cc1:Editor Id="editor" runat="server" Height="300px" />
This is inside a master page content container. However, when I run the page, the bold is never toggled on to start. What am I missing?
Also once at this point, how would I hide buttons I don't want to show? I found the page that says how to do that, but I can't do that with my project because its a web app, not a website with an app_code folder. Someone else said set the style to display none, but when I tried that that also didn't work.