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

Problems Setting focus client side

3 Answers 99 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 2
Kevin asked on 17 Oct 2008, 09:36 AM
Hi there,

I have a RadEditor that im injecting to a web page on the server side. and i wanted to set the focus when this is injected into the page to the Text box within the editor. on the server side just before i inject the code i add an event .onClientLoad. In the aspx of the page i'm adding i've added a function for onEditorClientLoad method which the onClientLoad method references.

In this onEditorClientLoad method i use the sender.setFocus(); method. however this doesnt seem to be doing the trick.. For some reason i think the sender variable is undefined?

Also I cannot seem to set the FocusOnLoad="true" This method is not avaliable to me? It would be great to just be able to set this property before I inject the Editor, Can you explain why this method is not avalible?

3 Answers, 1 is accepted

Sort by
0
Tervel
Telerik team
answered on 21 Oct 2008, 08:43 AM
Hello Kevin,

The property FocusOnLoad that you refer to exists in RadEditor Classic, and not RadEditor for ASP.NET AJAX.
More than 20 rarely used properties were removed or re-organized as part of our efforts to make the new editor much faster than the old one. If you compare their initialization time, the new editor takes 1/4th of the time needed for the old one (also its script is smaller, and it uses just a couple of image files, compared to the 60+ images needed to RadEditor Classic).

Hence, at present, some scenarios that were possible to realize with a property, now require a couple of lines of code.

From your message it is not clear what and how you have set, and what gets or does not get called on the client. It seems that you have not been able to set the OnClientLoad property and your function never gets called. You can easily test that by adding an alert statement to you first line of code in the function. The other possibility - that the sender variable can be null is not possible.

Here is the correct way to set the function on the server side:

RadEditor1.OnClientLoad = "MyOnClientLoadFunctionName";

Then in your page you need to make sure you have this function - you can add it to a script file or directly somewhere on the page, e.g.:

function MyOnClientLoadFunctionName(sender, args)
{
   sender.setFocus();
}

In case you get all things executing, but focus is still not there, it could be that some other control on the page is stealing the focus, so adding a small timeout will help, e.g.


function MyOnClientLoadFunctionName(sender, args)
{
    window.setTimeout(function() {sender.setFocus();}, 100);
}

Regards,
Tervel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Kevin
Top achievements
Rank 2
answered on 21 Oct 2008, 10:57 AM
Tervel,

That appears to be working in terms of setting the focus. Now for my second question. I assumed that by setting the focus that the Default tools would be set as such.. i.e the Paragraph is set to "Normal", Font would be set to Verdana, Real Font sized set to 70% and Remove Alignment selected. This happens when the user clicks on the control / as soon as they type. Is it possible to do this on focus (thought it would do it on focus anyways?!)

Cheers
Regards
Kevin R.
0
Tervel
Telerik team
answered on 21 Oct 2008, 02:13 PM
Hi Kevin,

Indeed - we will consider changing this behavior to raise the selectionChange event when calling setFocus.
For the time being we suggest you try the following to achieve your goal:

<script type="text/javascript">
function
OnClientLoad(editor)
{
   setTimeout(
function()
   {
         editor.set_html(editor.get_html());
   }, 0);
}
</script>


Kind regards,
Tervel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Editor
Asked by
Kevin
Top achievements
Rank 2
Answers by
Tervel
Telerik team
Kevin
Top achievements
Rank 2
Share this question
or