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

Set Rad Window Focus in server side while opening it

1 Answer 262 Views
Window
This is a migrated thread and some comments may be shown as answers.
Saniya
Top achievements
Rank 1
Saniya asked on 13 Mar 2012, 12:03 PM
Hi,

I have a rad window and for that I need to set the default button.Currently, when I hit the Enter key the button inside rad window is working only when my focus is inside the rad window. I need to set the focus to rad window when I open it in server side.

Can anyone help me out on this?

Thanks

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 14 Mar 2012, 04:33 PM
Hi Saniya,

This is the general way defaultButtons work - an input element in the respective panel (or form) must have focus in order for the enter key to trigger the default button action. This is explained in this article from MSDN.

Are you using the ContentTemplate of the RadWindow? If so - you can simply get a reference to the textbox and call its focus() method after showing the RadWindow, e.g.:

protected void OpenerButton_Click(object sender, EventArgs e)
{
    string script = "function f(){Sys.Application.remove_load(f);$find('" + rw1.ClientID + "').show(); $get('" + Textbox1.ClientID + "').focus();}Sys.Application.add_load(f);";
    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true); 
}

In case you are loading an external page you can execute a function in the content page to set the focus. How to do this is explained here. Note that this must be done in the OnClientPageLoad event, as the page will not be loaded before that. For example:
function OnClientPageLoad(sender, args)
{
    sender.get_contentFrame().contentWindow.setFocus();
}

where setFocus() is:
function setFocus()
{
    $get("<%=Textbox1.ClientID %>").focus();
}


Regards,
Marin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Window
Asked by
Saniya
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Share this question
or