【问题标题】:button event accidentally occured after textchangedtextchanged 后意外发生按钮事件
【发布时间】:2016-10-10 13:56:04
【问题描述】:

我对文本框上的 textchanged 事件有疑问。 在我输入一些字符串并按回车后,我不知道为什么按钮点击也会被触发

这是我的 .aspx

<form id="form1" runat="server">
<div>

</div>
    <asp:Label ID="labelKodeDivisi" runat="server" style="z-index: 1; left: 62px; top: 57px; position: absolute" Text="labelKodeDivisi"></asp:Label>
    <asp:Label ID="labelNamaDivisi" runat="server" style="z-index: 1; left: 62px; top: 85px; position: absolute" Text="labelNamaDivisi"></asp:Label>
    <asp:Button ID="butLogout" runat="server" OnClick="butLogout_Click" style="z-index: 1; left: 682px; top: 40px; position: absolute" Text="Button" />
    <asp:TextBox ID="tbKode" runat="server" OnTextChanged="tbKode_TextChanged" style="z-index: 1; left: 71px; top: 127px; position: absolute"></asp:TextBox>
</form>

这里是我的 aspx.cs

public partial class FormDivisi2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void butLogout_Click(object sender, EventArgs e)
    {
        labelKodeDivisi.Text = "123";
    }

    protected void tbKode_TextChanged(object sender, EventArgs e)
    {
        labelNamaDivisi.Text = "555";
    }
}

发生的情况是,当我在文本框 tbKode 中输入文本并按 Enter 键时,labelNamaDivisi.text 更改为 555,但 labelKodeDivisi.text 也更改为 555。 我想要的是当我在文本框 tbKode 中输入一些文本时,labelNamaDivisi.text 更改为 555 但 labelKodeDivisi 没有更改。 labelKodeDivisi 仅在我按下按钮但注销时更改

【问题讨论】:

标签: c# asp.net button textbox textchanged


【解决方案1】:

你可以试试这个

$('input').keypress(function(event){
        if(event.keyCode==13)
        {
            event.preventDefault();

            }
        })

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多