0
votes

I am writing an asp.net page, and I'm having some trouble submitting the form. What I have is a multiline text box. When the user hits enter, the form should submit, but instead it is inserting a new line (this is usually the opposite problem people have). Here is the relevant body code:

<div align="left">
        Name:

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

            <asp:Button ID="Clear" runat="server" onclick="Clear_Click" 
                Text="Clear Chat Log" UseSubmitBehavior="False" />

        </div>
        <br />
        <asp:UpdatePanel runat="server" UpdateMode="Conditional">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="UpdateTimer" EventName="Tick"/>
                <asp:AsyncPostBackTrigger ControlID="Go" EventName="Click" />
            </Triggers>
            <ContentTemplate>
                <asp:TextBox id="Chat" runat="server" ReadOnly="true" TextMode="MultiLine" Width="400" Height="630" />
                <asp:Timer runat="server" Interval="500" OnTick="Timer_Tick" ID="UpdateTimer"/>
            </ContentTemplate>
        </asp:UpdatePanel>
        <asp:UpdatePanel runat="server" UpdateMode="Conditional">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Go" EventName="Click" />
            </Triggers>
            <ContentTemplate>
                <br/>
                <asp:TextBox id="Message" runat="server" Width="400" Wrap="true" Height="40px" 
                    TextMode="MultiLine" AutoCompleteType="Disabled" AutoPostBack="True"/>
                <asp:Button id="Go" runat="server" Text="Go" Width="40px" Height="40px" OnClick="goClicked" UseSubmitBehavior="true"/>
            </ContentTemplate>
        </asp:UpdatePanel>

My guess is that the problem is the update panels. Basically, the "Go" button should fire if the user hits enter in the "Message" textbox (these are both at the bottom of the listing)

Thanks for your help, Max

3

3 Answers

1
votes

You need to trap the key Enter at multiline textbox and then submit the form; with Javascript. A sample:

<input type="text" id="txtMultiline" onkeydown="if(event.keyCode == 13) document.getElementById('btnSubmit').click()"/>
0
votes

Try Ctrl+Enter. Plus, Facebook message page has similar behavior, but you can select the mode: "Quick reply" vs button.

0
votes

Add another TextBox, like this:

<asp:TextBox ID="txtSubmitOnEnter" runat="server" Width="0" style="visibility:hidden;display:none;" />      

It should work after that.