Make an asp: TextBox inside the repeater, run the Repeater ItemCommand when Enter pressed

I have a repeater containing TextBoxes and LinkButtons. When I click LinkButton, the ItemCommand event fires normally. When I press Enter in any of the text fields, the form in which the repeater is located will be sent. Ideally, I would like the behavior to be that hitting the enter key in the text box performs the same action as hitting the LinkButton button, so I guess either I have to programmatically β€œclick” LinkButton when the button is clicked, or I need way to run the same ItemCommand (with the appropriate command name / argument) that LinkButton does

Can someone let me know how this will be achieved? Thanks

+4
source share
1 answer

Here is a possible approach. You basically wrap the TextBox and LinkButton in a panel. The panel provides the ability to specify the default button - this is the button that will be pressed when the user presses Enter in the text box 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 a problem with the default LinkButton parameter may occur in FF - here is a message describing both the problem and the solution. However, this may be outdated - the message was written in 2007, since then everything could have changed.

+4
source

Source: https://habr.com/ru/post/1495903/


All Articles