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

Focus lost in RadWindow

3 Answers 183 Views
Window
This is a migrated thread and some comments may be shown as answers.
Datamex
Top achievements
Rank 2
Datamex asked on 22 Sep 2009, 03:54 PM
Hi,

I have a RadWindow in which a page is shown, containing a form. I wish the first RadTextBox in that Form to have focus, which works as it should when the page is loaded directly.
But, when I load the page in a RadWindow (dynamically, as it uses a QueryString for parameters, so the url is set from javascript), none of the Controls have focus.
I have altered the page by adding a line that explicitly sets focus to the control in the page load event, but it didn't work. I finally discovered, that setting ShowContentDuringLoad="true" on the RadWindow solved the problem. But that has a negative effect, because if the RadWindow is opened a second time (with a different QueryString), the old page is displayed while the new is loading, which gives a strange effect.

I have tried adding a javascript function to the onload event of the page, which sets focus to the RadTextBox, but even that seems cancelled by the RadWindow.

How can I make sure that the RadTextBox has focus after opening the page in a RadWindow?

3 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 23 Sep 2009, 12:22 PM
Hello Datamex,

In this case I suggest to use RadTextBox's client-side API and to call its focus() method in the ASP.NET AJAX's pageLoad() function (it is automatically called when all ASP.NET AJAX controls are loaded on the page).
e.g.
<script type="text/javascript"
 
    function pageLoad() 
    { 
        var radtextbox = $find("<%= RadTextBox1.ClientID %>"); 
        radtextbox.focus(); 
    } 
 
</script> 
 
<asp:TextBox ID="txt1" runat="server"></asp:TextBox><br /> 
<telerik:RadTextBox ID="RadTextBox1" runat="server"
</telerik:RadTextBox> 
<br /> 
<asp:TextBox ID="txt2" runat="server"></asp:TextBox> 


Regards,
Georgi Tunev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Datamex
Top achievements
Rank 2
answered on 23 Sep 2009, 12:54 PM
Hello Georgi,

The solution you proposed yields the same results. But I have discovered something strange: both setting focus from codebehind as well as setting it from JavaScript (either the onload= and pageLoad() approach) work when I have a breakpoint on the line that sets focus and wait a little while before pressing play again.

I have tried adding a Thread.Sleep(1000) call in the codebehind (which is not much of a fix, but just a try), but even giving it a long time to sleep would not yield the same result as pausing on a breakpoint.

Using Firebug and pausing on a breakpoint in the JavaScript also solved the problem. I haven't been able to try a Thread.Sleep equivalent in JavaScript, as JavaScript doesn't support waiting.

As a last remark, I'd like to point out that I have been using Firefox for testing. If I try your solution in IE8, it works as it should.
0
Georgi Tunev
Telerik team
answered on 23 Sep 2009, 01:30 PM
Hello Datamex,

Thank you for the feedback - now I was able to reproduce the problem. I suggest using a small timeout in such case - just enough to allow the browser to properly focus the textbox (when ShowContentDuringLoad is set to false, the initial size of the RadWindow's IFRAME is 0x0 pixels and after the page is loaded, it is "stretched" to fill the window content area).

function pageLoad() 
    window.setTimeout(function() 
    { 
        var radtextbox = $find("<%= RadTextBox1.ClientID %>"); 
        radtextbox.focus(); 
    }, 100); 


Greetings,
Georgi Tunev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Window
Asked by
Datamex
Top achievements
Rank 2
Answers by
Georgi Tunev
Telerik team
Datamex
Top achievements
Rank 2
Share this question
or