Logout button intercept enter key

605 Views Asked by At

I have asp.net page like this: There is a form that contains all, inside it a LoginStatusand some other controls like TextBox and ImageButton.

My problem is that: when we press Enter in the Text box, the LogOut button is pressed, then the user goes out. There is a way to avoid it?

I tried with javascript, but my controls are inside ajax panel and it is very complex, there is a html way?

Regards, Antonino

1

There are 1 best solutions below

0
VDWWD On

Wrap the TextBox or the HTML containing the TextBox with something like this:

<div onKeyDown="return (event.keyCode!=13);"> ... </div>

If you do want something to happen when the enter key is pressed other than the LogOut button you can wrap the content inside a Panel and assign a DefaultButton like this:

<asp:Panel ID="Panel1" runat="server" DefaultButton="Button2">

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>

    <asp:Button ID="Button1" runat="server" Text="LogOut" />
    <asp:Button ID="Button2" runat="server" Text="Cancel" />

</asp:Panel>

Now when the enter key is pressed in either TextBox the Cancel button will fire.