Identifying main submit button for a form

孤人 提交于 2019-12-02 09:24:37

Its pretty tough to get more native than javascript. You're gonna need it here. By the way, the behavior you noticed is the expected behavior. The first submit button in your html is the one that will get sent with your header.

I guess if you really didn't want to use js, you could just put the other button first and then use css to position them correctly on the page itself.

If you are using asp .net then you can use "UseSubmitBehavior" property on the button. See below code.

<asp:TextBox runat="server" ID="txt1"></asp:TextBox> <br/>
    <asp:Button runat="server" ID="btn1" UseSubmitBehavior="False" Text="1" OnClick="test1"/> <br/>
    <asp:Button runat="server" ID="btn2" UseSubmitBehavior="True" Text="2" OnClick="test2"/>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!