<p>I have some C# / asp.net code I inherited which has a textbox which I want to make multiline. I did so by adding textmode="multiline" but when I try to insert a newline, the enter key instead submits the form :P</p>

<p>I googled around and it seems like the default behavior should be for enter (or control-enter) to insert a newline. Like I said I inherited the code so I'm not sure if there's javascript monkeying around or if there's just a simple asp.net thing I have to do.</p>

[{'answer_id': 30246, 'author': 'juan', 'author_id': 1782, 'author_profile': 'https://Stackoverflow.com/users/1782', 'pm_score': 0, 'selected': False, 'text': "<p>I suspect it's (like you say) some custom javascript code.</p>\n\n<p>The original asp.net control works fine... you are going to have to check the code</p>\n"}, {'answer_id': 30248, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 0, 'selected': False, 'text': '<p>Are you handling the textchanged event for the textbox?  That would mean ASP.Net sets the textbox to cause a postback (submit the page) for anything the <em>might</em> cause the textbox to lose focus, including the enter key.</p>\n'}, {'answer_id': 30261, 'author': 'samjudson', 'author_id': 1908, 'author_profile': 'https://Stackoverflow.com/users/1908', 'pm_score': 1, 'selected': False, 'text': '<p>I created a sample page with a TextBox and a Button and it worked fine for me:</p>\n\n<pre><code>&lt;asp:TextBox runat="server" ID="textbox1" TextMode="MultiLine" /&gt;\n&lt;br /&gt;\n&lt;br /&gt;\n&lt;asp:Button runat="server" ID="button1" Text="Button 1" onclick="button1_Click" /&gt;\n</code></pre>\n\n<p>So it most likely depends on either some other property you have set, or some other control on the form.</p>\n\n<p>Edit: TextChanged event is only triggered when the TextBox loses focus, so that can\'t be the issue.</p>\n'}, {'answer_id': 30372, 'author': 'Dave Ward', 'author_id': 60, 'author_profile': 'https://Stackoverflow.com/users/60', 'pm_score': 1, 'selected': False, 'text': '<blockquote>\n  <p>I can\'t find that "WebForm_FireDefaultButton" javascript anywhere, is it something asp.net is generating?</p>\n</blockquote>\n\n<p>Yes.</p>\n\n<p>That\'s generated to support the <strong>DefaultButton</strong> functionality of the form and/or Panel containing your controls.  This is the source for it:</p>\n\n<pre><code>function WebForm_FireDefaultButton(event, target) {\n  if (event.keyCode == 13) {\n    var src = event.srcElement || event.target;\n    if (!src || (src.tagName.toLowerCase() != "textarea")) {\n      var defaultButton;\n      if (__nonMSDOMBrowser) {\n        defaultButton = document.getElementById(target);\n      }\n      else {\n        defaultButton = document.all[target];\n      }\n      if (defaultButton &amp;&amp; typeof (defaultButton.click) != "undefined") {\n        defaultButton.click();\n        event.cancelBubble = true;\n        if (event.stopPropagation) event.stopPropagation();\n        return false;\n      }\n    }\n  }\n  return true;\n}\n</code></pre>\n'}, {'answer_id': 30826, 'author': 'adambox', 'author_id': 2462, 'author_profile': 'https://Stackoverflow.com/users/2462', 'pm_score': 0, 'selected': False, 'text': '<p>@dave-ward, I just dug through mounds of javascript. most was ASP.NET generated stuff for validation and AJAX, there\'s a bunch starting with "WebForm_" that I guess is standard stuff to do the defaultbutton, etc. the only javascript we put on the page is for toggling visibility and doing some custom validation...</p>\n\n<p>edit: I did find the below. I don\'t understand it though :P the beginning of the form the textarea is in, and a script found later: (note, something on stackoverflow is messing with the underscores)</p>\n\n<pre><code>&lt;form name="Form1" method="post" action="default.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="Form1"&gt;\n\n&lt;script type="text/javascript"&gt;\n//&lt;![CDATA[\nvar theForm = document.forms[\'Form1\'];\nif (!theForm) {\n    theForm = document.Form1;\n}\nfunction __doPostBack(eventTarget, eventArgument) {\n    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {\n        theForm.__EVENTTARGET.value = eventTarget;\n        theForm.__EVENTARGUMENT.value = eventArgument;\n        theForm.submit();\n    }\n}\n//]]&gt;\n&lt;/script&gt;\n</code></pre>\n'}, {'answer_id': 32358, 'author': 'adambox', 'author_id': 2462, 'author_profile': 'https://Stackoverflow.com/users/2462', 'pm_score': 3, 'selected': True, 'text': '<p>It turns out this is a bug with Firefox + ASP.NET where the generated javascript for the defaultButton stuff doesn\'t work in Firefox. I had to put a replacement for the WebForm_FireDefatultButton function as described <a href="http://forums.asp.net/t/1294544.aspx" rel="nofollow noreferrer">here</a>:</p>\n\n<pre><code>function WebForm_FireDefaultButton(event, target) {\n    var element = event.target || event.srcElement;\n    if (event.keyCode == 13 &amp;&amp;\n    !(element &amp;&amp;\n    element.tagName.toLowerCase() == "textarea"))\n    {\n        var defaultButton;\n        if (__nonMSDOMBrowser)\n        {\n            defaultButton = document.getElementById(target);\n        }\n        else\n        {\n            defaultButton = document.all[target];\n        }\n        if (defaultButton &amp;&amp; typeof defaultButton.click != "undefined")\n        {\n            defaultButton.click();\n            event.cancelBubble = true;\n            if (event.stopPropagation)\n            {\n                event.stopPropagation();\n            }\n            return false;\n        }\n    }\n    return true;\n}\n</code></pre>\n'}, {'answer_id': 377887, 'author': 'Bret Walker', 'author_id': 8797, 'author_profile': 'https://Stackoverflow.com/users/8797', 'pm_score': 0, 'selected': False, 'text': '<p><a href="http://blog.codesta.com/codesta_weblog/2007/12/net-gotchas---p.html" rel="nofollow noreferrer">http://blog.codesta.com/codesta_weblog/2007/12/net-gotchas---p.html</a> worked for me.</p>\n'}, {'answer_id': 30205993, 'author': 'Kashyap Tank', 'author_id': 4894117, 'author_profile': 'https://Stackoverflow.com/users/4894117', 'pm_score': -1, 'selected': False, 'text': '<p>you can use \\n for enter key \ni.e.\n  [a-zA-Z 0-9/.\\n]{20,500}</p>\n'}]
['https://Stackoverflow.com/questions/30230', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2462/']