进入关键原因不必要后回 [英] Enter key causes the unnecessary post-back

查看:213
本文介绍了进入关键原因不必要后回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在vb.net一个网络申请表。
当我点击一个单选按钮,回传在服务器上运行。如果我preSS进入的同时会引起另一回发到服务器。我如何prevent是第二回发?

 < TD类=tdClassicID =tdCT>
< ASP:单选按钮ID =rbSingle=服务器文本=SINGL的AutoPostBack =真正的组名=grpT/>
< ASP:单选按钮ID =rbMultiple=服务器文本=多的AutoPostBack =真正的组名=grpTrainer/>
< / TD>


解决方案

如果您正在使用jQuery你可以使用提交表单停止endter键:

 的$(document).KEY preSS(函数(五)
{
    如果(e.key code === 13)
    {
        亦即preventDefault();
        返回false;
    }
});

如果不是这可能工作:

 < SCRIPT LANGUAGE =JavaScript的>
VAR NAV = window.Event?真假;
如果(NAV){
window.captureEvents(Event.KEYDOWN);
window.onkeydown = NetscapeEventHandler_KeyDown;
}其他{
document.onkeydown = MicrosoftEventHandler_KeyDown;
}功能NetscapeEventHandler_KeyDown(五){
如果(e.which == 13安培;&安培; e.target.type ='文本区域'和;!&安培;!e.target.type ='提交'){
返回false;
}
返回true;
}功能MicrosoftEventHandler_KeyDown(){
如果(event.key code == 13安培;&安培;!event.srcElement.type ='文本区域'和;&安培;
event.srcElement.type!=提交)
返回false;
返回true;
}
< / SCRIPT>

或者如果你有页面上的按钮,然后 UseSubmitBehavior 可能是一个更好的解决方案:

 < ASP:按钮的ID =Button1的文本=提交的onclick =SubmitBtn_Clickusesubmitbehavior =假=服务器/>

看<一个href=\"https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.usesubmitbehavior.aspx\" rel=\"nofollow\">https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.usesubmitbehavior.aspx

I have a web-application form in vb.net. When I click on a radio button, a postback is run on the server. If I press enter at the same time it causes another postback to the server. How do I prevent that second postback?

<td class="tdClassic" id="tdCT">
<asp:RadioButton ID="rbSingle" runat="server" Text="Singl" AutoPostBack="true" GroupName="grpT" />
<asp:RadioButton ID="rbMultiple" runat="server" Text="Multiple" AutoPostBack="true" GroupName="grpTrainer" />
</td>

解决方案

If you are using jQuery you can stop the endter key from submitting the form using:

$(document).keypress(function(e)
{
    if(e.keyCode === 13)
    {
        e.preventDefault();
        return false;
    }
});

if not this might work:

<script language="JavaScript">
var nav = window.Event ? true : false;
if (nav) {
window.captureEvents(Event.KEYDOWN);
window.onkeydown = NetscapeEventHandler_KeyDown;
} else {
document.onkeydown = MicrosoftEventHandler_KeyDown;
}

function NetscapeEventHandler_KeyDown(e) {
if (e.which == 13 && e.target.type != 'textarea' && e.target.type != 'submit') { 
return false; 
}
return true;
}

function MicrosoftEventHandler_KeyDown() {
if (event.keyCode == 13 && event.srcElement.type != 'textarea' && 
event.srcElement.type!= 'submit')
return false;
return true;
}
</script>

or if you have a button on the page then UseSubmitBehavior might be a better solution:

<asp:button id="Button1" text="Submit" onclick="SubmitBtn_Click"    usesubmitbehavior="false" runat="server"/>

see https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.usesubmitbehavior.aspx

这篇关于进入关键原因不必要后回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆