开发者

Stop Textbox firing OnClientClick event

The combination of pressing enter on a textbox with a page that has an image button with both a client and server click event is causing the client side event to fire when I press enter in the textbox.

I want to prevent this, am happy to use Jquery or whatev开发者_运维知识库er is best. From the Jquery side am struggling to capture the enter key

<asp:TextBox ID="tbName" runat="server"></asp:TextBox>

<asp:ImageButton ID="CancelImageButton" ImageUrl="Cancel.gif"   
runat="server"  OnClientClick="alert(); return false;" 
onclick="Cancel_Click"/>


If you're not using server-side and client-side TextBox's events, why don't you try HtmlInputText?

  • http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlinputtext(v=VS.100).aspx

So you can use jQuery to bind an event handler to this control.

Perhaps you can take a look to this jQuery event object method:

  • http://api.jquery.com/event.stopPropagation/


I have tested at my end and found you did not pass the alert message. That's why it is not working.

 OnClientClick="javascript:alert('Hello'); return false;"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜