Set focus to a button within a rad window

4 posts, 0 answers
  1. saravanan k
    saravanan k avatar
    88 posts
    Member since:
    Mar 2010

    Posted 15 Nov 2012 Link to this post

    [Correct title of the post] - Click a button on press of enter key

    Hi Folks,

    I have a rad window, which has some text content and 'Yes' & 'No' buttons. [Note, there are no text boxes present].
    When the enter button is pressed, the 'Yes' button click must be triggered.

    How do I do this?

    Regards,
    Saravanan
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 15 Nov 2012 Link to this post

    Hi saravanan,

    Following is the sample code that I tried to set focus to a button inside the RadWindow.

    ASPX:
    <telerik:RadWindow VisibleOnPageLoad="true" OnClientShow="OnWindowShow" ID="RadWindow3" runat="server" Height="300px" Width="450px" Modal="true">
        <ContentTemplate>
            <%--  your text--%>
            <asp:Button ID="Button1" runat="server" Text="Yes" OnClick="Button1_Click" />
            <asp:Button ID="Button2" runat="server" Text="No" OnClick="Button2_Click" />
        </ContentTemplate>
    </telerik:RadWindow>

    JS:
    <script type="text/javascript">
        var obj;
        function pageLoad() {
            obj = $get("<%=Button1.ClientID %>");
        }
        function OnWindowShow(sender, args) {
            setTimeout(" obj.focus();", 200);
        }
    </script>

    Hope this helps.

    Regards,
    Princy.
  3. saravanan k
    saravanan k avatar
    88 posts
    Member since:
    Mar 2010

    Posted 15 Nov 2012 Link to this post

    Thanks Princy.

    I have worded the title of this post incorrectly.

    What I really need is, on press of enter button, the 'Yes' button has to be automatically clicked.

    Regards,
    Sara
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 15 Nov 2012 Link to this post

    Hi saravanan,

    The above code snippet helps to set focus to the Button1 which is inside the RadWindow and on clicking on the Enter key the click event of Button1 will be triggered.

    Hope this helps.

    Regards,
    Princy.
Back to Top