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

Keypress on button

3 Answers 114 Views
Button
This is a migrated thread and some comments may be shown as answers.
Fabio Cirillo
Top achievements
Rank 1
Fabio Cirillo asked on 04 Feb 2013, 02:05 PM
hi,
I have two buttons (button1 and button2) and for each of these buttons I have 2 textbox login. I wish that when I write in the first textbox and hit the enter button on your computer, it must start button code button1 or if I write in the second textbox and hit the enter button to start the second button button2 code .... I tried but it always starts code written in the first button. So I decided to disable the keypress event = 13 across the page. But now my client wants the buttons function by pressing the "enter" key.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 05 Feb 2013, 04:35 AM
Hi Fabio

Try putting both buttons and textbox inside asp Panels respectively and try setting its DefaultButton property to the buttons ID
So if once the focus comes to the first textbox and you click enter first button will hit and if the focus comes to the second textbox and you click enter the second buton gets fired.

Thanks
Princy
0
Fabio Cirillo
Top achievements
Rank 1
answered on 10 Feb 2013, 10:05 PM
hi,
can you send me a example?
0
Princy
Top achievements
Rank 2
answered on 11 Feb 2013, 06:32 AM
Hi,

Try the following code to achieve your scenario.
aspx:
<asp:Panel ID="Panel1" runat="server" DefaultButton="Button1">
            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</asp:Panel>
        <asp:Panel ID="Panel2" DefaultButton="Button2" runat="server">
            <asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" />
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</asp:Panel>

Thanks,
Princy
Tags
Button
Asked by
Fabio Cirillo
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Fabio Cirillo
Top achievements
Rank 1
Share this question
or