I have "ClickonEnterKey" and "ClickonSpaceKey" both set to false and the image button is still catching the Enter key and firing the click event. What could be the problem?
Hi,
I retested functionality of ClickOnEnterKey='false' and it worked correctly.Note: that property has effect only when focus belongs to WebImageButton.
However, if focus belongs to some other html elements on page, like <input> of asp:TextBox or similar and user pressed Enter, then browser may behave quite strange and unexpected way. For example, browser may search for first "button" element on page and trigger "click" event for that element. If similar happens and that element is <input> of WebImageButton, then WebImageButton has no way to know what was the actual event of browser. The only WebImageButton can do is to check "event.type", so it is "click, then WebImageButton acts accordingly to click, but not Enter-down.
You may run following codes, click on TextBox and hit Enter key. You probably will get alert will tell you, that button was clicked and postback will happen. But in reality that Enter-down has nothing to do with Button1, but with TextBox1
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="alert('button1')" /> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
You may verify that WebImageButton behaves correctly, if you run following and try to test Alt+R, mouseclick, focus+space, focus+enter. To set focus to WebImageButton you may use Tab-key or mouse down on button and mouse-drag-off.To see focus+enter, you should remove ClickOnEnterKey=false.If you insert asp:Button in front of WebImageButton, set focus to textbox and hit enter, then that asp:Button will get "click" event, but not WebImageButton.
<script type="text/javascript">function WebImageButton1_Click(oButton, oEvent){ alert('action:' + oEvent.action + '\nwhere: 0-click, 1-space, 2-enter, 3-accesskey');}</script><igtxt:WebImageButton ID="WebImageButton1" runat="server" ClickOnEnterKey="false" Text="ImageBut" AccessKey="R"> <ClientSideEvents Click="WebImageButton1_Click" /></igtxt:WebImageButton><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
If you want to prevent postback on enter key globally, then you may process keydown on level of body, document or form, check for enter key and cancel event. Below is the simplest example for that:
<script type="text/javascript">function filterKey(event){ if (event && event.keyCode == 13) ig_cancelEvent(event);}</script><form id="form1" runat="server" onkeydown="filterKey(event)">
I am experianceing the same problem, has the infragistics team came up with a solution yet in this problem?