Pressing Enter Key in a Multiline TextBox causes a Postback in FireFox




One of our http://www.dotnetcurry.com/ authors Malcolm Sheridan informed me that when he is replying to a viewer who has left comments and enters text in the Comment field, he can't hit the enter key to start a new paragraph or a new line because doing so causes a postback in FireFox. The Comment field happens to be a Multiline TextBox and the issue is seen in the FireFox browser.

Well if you are facing a similar issue and are looking out for a solution, here it is.

<asp:TextBox ID="txtBody" onkeypress="event.cancelBubble=true;"
runat="server" Text='<%# Bind("Body") %>' TextMode="MultiLine"
Rows="5" Width="100%"></asp:TextBox>

Observe how I have used event.cancelBubble=true on the keypress event. This property determines whether the current event should bubble up the hierarchy of event handlers. Setting it to true disables bubbling for the event and does not cause a postback when the Enter key is pressed.

Read more on the cancelBubble Property over here



Will you give this article a +1 ? Thanks in advance




About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

1 Response to "Pressing Enter Key in a Multiline TextBox causes a Postback in FireFox"
  1. Soetam Rizky said...
    July 23, 2009 at 5:46 PM

    Just know it now that there is a property called cancelbubble....
    Thx for the info....

 

Copyright © 2009-2014 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions