Search code examples
c#asp.nettabindexbuttonclick

button_click upon pressing Return in TextBox - ASP.NET


I've got an ASP WebForm with 2 Textboxes and 3 Buttons and I want a specific button_click event to be fired whenever I press return whilst in a TextBox - how would I achieve this?

I tried using the TabIndex-Property, unfortunately that actually only seems to work for tabbing, not for pressing return in a TextBox.

Thanks!


Solution

  • Hey everyone, thanks for your answers - I just found the solution, for an aspx-page within a MasterPage I need to set

    Form.DefaultButton = myButton.UniqueID;
    

    instead of

    Form.DefaultButton = myButton.ID;
    

    which throws an error.

    Thanks everyone!