ASP.NET输入密钥和表单提交没有javascript

时间:2022-11-24 09:36:35

I have a form that I want to submit when the user presses the enter key. It works fine in Firefox, but not in IE. It is basically the same issue as this, except that I am not allowed to use any JavaScript: Enter button does not submit form (IE ONLY) ASP.NET

我有一个表单,我想在用户按下回车键时提交。它适用于Firefox,但不适用于IE。它与此基本相同,只是我不允许使用任何JavaScript:Enter按钮不提交表单(仅限IE)ASP.NET

Unfortunately it looks like ASP.NET uses JavaScript to process the button postback. Is there a way around this issue that doesn't rely on JavaScript?

不幸的是,看起来ASP.NET使用JavaScript来处理按钮回发。有没有办法绕过这个不依赖JavaScript的问题?

2 个解决方案

#1


The fix for this is what was listed in the bottom of the page of your linked post. IE needs to have an additional form field for some reason for this to work. I have used this in many projects, and it gets around the bug. Just add the following.

对此的修复是链接帖子页面底部列出的内容。由于某种原因,IE需要有一个额外的表单字段才能工作。我在很多项目中都使用过这个,它可以解决这个问题。只需添加以下内容。

<!-- Fix for IE bug submit on pressing "Enter") -->
<div style="display:none">
            <input type="text" name="hiddenText"/>
</div>

#2


My solution was this, a script that does click the login button.

我的解决方案就是这个,一个单击登录按钮的脚本。

Worked in all browsers!

适用于所有浏览器!

public partial class Logon : UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.ClientScript.RegisterClientScriptBlock(GetType(), "Logon", "document.getElementById('id_LoginButton').click();", true);
    }
}

#1


The fix for this is what was listed in the bottom of the page of your linked post. IE needs to have an additional form field for some reason for this to work. I have used this in many projects, and it gets around the bug. Just add the following.

对此的修复是链接帖子页面底部列出的内容。由于某种原因,IE需要有一个额外的表单字段才能工作。我在很多项目中都使用过这个,它可以解决这个问题。只需添加以下内容。

<!-- Fix for IE bug submit on pressing "Enter") -->
<div style="display:none">
            <input type="text" name="hiddenText"/>
</div>

#2


My solution was this, a script that does click the login button.

我的解决方案就是这个,一个单击登录按钮的脚本。

Worked in all browsers!

适用于所有浏览器!

public partial class Logon : UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.ClientScript.RegisterClientScriptBlock(GetType(), "Logon", "document.getElementById('id_LoginButton').click();", true);
    }
}