I've got a repeater that contains TextBoxes and LinkButtons. When I click the LinkButton, the ItemCommand event fires OK. Wwhen I press Enter in any of the textboxes, the form that the repeater is inside is submitted. Ideally I'd want the behaviour to be that pressing enter in the textbox performs the same action as clicking the LinkButton does - so I figure that either I have to programmatically "click" the LinkButton when enter is pressed, or I need a way to fire the same ItemCommand (with the relevant command name/ argument) event that the LinkButton does
Could anyone give me a clue as to how this would be achieved? Thanks
Here is a possible approach. Basically you wrap TextBox
and LinkButton
into the panel. Panel provides an option to specify a default button - that is a button that will be clicked when user hits Enter
in the textbox inside this panel.
<ItemTemplate>
<asp:Panel ID="Panel1" runat="server" DefaultButton="LinkButton1">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Cmd" Text="FireCmd"/>
</asp:Panel>
</ItemTemplate>
Beware that there might be a problem in FF with LinkButton
being default - here is a post describing both problem and solution. However it might be outdated - post was written in 2007, things might have changed since then.