Set Rad Window Focus in server side while opening it

2 posts, 0 answers
  1. Saniya
    Saniya avatar
    2 posts
    Member since:
    Feb 2012

    Posted 13 Mar 2012 Link to this post

    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
  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    5243 posts

    Posted 14 Mar 2012 Link to this post

    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.
Back to Top