简体   繁体   English

在按下Enter键时,在Repeater中创建一个asp:TextBox会触发Repeater的ItemCommand

[英]Make an asp:TextBox inside a Repeater fire the Repeater's ItemCommand when Enter pressed

I've got a repeater that contains TextBoxes and LinkButtons. 我有一个包含TextBoxes和LinkBut​​tons的转发器。 When I click the LinkButton, the ItemCommand event fires OK. 当我单击LinkBut​​ton时,ItemCommand事件触发OK。 Wwhen I press Enter in any of the textboxes, the form that the repeater is inside is submitted. 当我在任何文本框中按Enter键时,将提交转发器所在的表单。 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 理想情况下,我希望行为是在文本框中按下输入执行与单击LinkBut​​ton相同的操作 - 所以我想要在按下enter时以编程方式“点击”LinkBut​​ton,或者我需要一种方法触发与LinkBut​​ton相同的ItemCommand(带有相关的命令名/参数)事件

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. 基本上你将TextBoxLinkButton包装到面板中。 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. Panel提供了一个指定默认按钮的选项 - 当用户在此面板内的文本框中点击Enter ,该按钮将被点击。

<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. 请注意,在LinkButton默认情况下FF可能存在问题 - 这是一篇描述问题和解决方案的帖子 However it might be outdated - post was written in 2007, things might have changed since then. 然而它可能已经过时了 - 帖子是在2007年写的,事情可能从那时起发生了变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM