-1

I find this but It doesn't work with me

How to disable submit behaviour of asp:ImageButton?

and this my html

<td class="style101">  
    <asp:ImageButton ID="imgBtnPost" runat="server" Height="30px" 
         ToolTip="posting" ImageUrl="~/images/postvoucher.jpg" 
         onclick="ImageButton4_Click" Width="39px" />
</td>
Shireen
  • 167
  • 1
  • 2
  • 15
rawan
  • 27
  • 8
  • please give some more informations, what does not work, with what browser, what error did you get ? what do you have try ? – Aristos Feb 06 '15 at 17:01
  • you can check KeyPress Events cab you show the `codebehind` that you have associated with the onClick also based on the link that you provided not sure why it doesn't work for you.. did you add the `javascript code` please show all relevant code – MethodMan Feb 06 '15 at 17:03
  • I tryed to add the jquery in body and before style jQuery.fn.DisableEnterKey = function() { return this.each(function() { $(this).keydown(function(e) { var key = e.charCode || e.keyCode || 0; // return false for the enter key return (key != 13); }) }) }; // You can then wire it up by just adding this code for each control: – rawan Feb 06 '15 at 17:50

2 Answers2

0

One way to do it from code behind. It will prevent the post back to the server (MSDN):

imgBtnPost.Enabled = false;
Red
  • 818
  • 2
  • 14
  • 26
0

The link in your question is to disable pressing Enter key inside textbox.

Another approach is you can disable Enter Key press in an entire page. Obviously, you only want that feature in a specific page.

For example,

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
    $('form').on("keyup keypress", function (e) {
        var code = e.keyCode || e.which;
        if (code == 13) {
            e.preventDefault();
        }
    });

</script>
<asp:TextBox runat="server" ID="TextBox1"/>
<asp:ImageButton ID="imgBtnPost" runat="server"
    OnClick="ImageButton4_Click" ... />
Community
  • 1
  • 1
Win
  • 61,100
  • 13
  • 102
  • 181
  • I added the code you gave it to me but the enter still working I will describe what exactly I want the web form include drop down list , 4 text box and image button when am in first text box and the user hit enter key goes directly to image button i want to disable that – rawan Feb 06 '15 at 18:02
  • My code works. Create a new ASPX page (without master page) and test it. The problem is if your existing ASPX page has JavaScript error, other JavaScript will stop working too. Also make sure you include jQuery library. – Win Feb 06 '15 at 18:30