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

Set focus to a button within a rad window

3 Answers 175 Views
Window
This is a migrated thread and some comments may be shown as answers.
saravanan k
Top achievements
Rank 1
saravanan k asked on 15 Nov 2012, 09:05 AM
[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

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 15 Nov 2012, 09:47 AM
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.
0
saravanan k
Top achievements
Rank 1
answered on 15 Nov 2012, 10:45 AM
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
0
Princy
Top achievements
Rank 2
answered on 16 Nov 2012, 03:33 AM
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.
Tags
Window
Asked by
saravanan k
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
saravanan k
Top achievements
Rank 1
Share this question
or