Canceling the default submit button in ASP.NET

自闭症网瘾萝莉.ら 提交于 2019-11-27 14:37:57
David

You can set the button's UseSubmitBehavior = false

btnCategory.UseSubmitBehavior = false;

Here is what I used to fix this problem.

<form runat="server" defaultbutton="DoNothing">
        <asp:Button ID="DoNothing" runat="server" Enabled="false" style="display: none;" />

I also had this problem with an ImageButton on my MasterPage (the Logout button) being set as the default button (so whenever someone pressed Enter, it would log them out). I solved it by using the following line in the Page_Load event on every child page, which is a bit of a work-around, but it works:

Form.DefaultButton = cmdSubmit.UniqueID;

Hope this helps someone else.

<asp:TextBox ID="TXT_Quality" runat="server" Width="257px" 
onkeypress="return key_Pressed(event, this);">
</asp:TextBox>   

function key_Pressed(e, textarea)
 {
    var code = (e.keyCode ? e.keyCode : e.which);
    if(code == 13) 
    { 
       return false;
    }
    return true;
 }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!