1

I have a problem with textchanged event on textbox. After i input some string and hit enter, i don't know why button click is fired too

here my .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>

and here my 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";
    }
}

Whats going on is, when i input text in textbox tbKode and hit enter, labelNamaDivisi.text change to 555 but labelKodeDivisi.text also change to 555. What i want is when i input some text in textbox tbKode, labelNamaDivisi.text change to 555 but labelKodeDivisi not change. labelKodeDivisi only change when i hit button butLogout

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • See http://stackoverflow.com/questions/4209903/asp-net-page-enter-key-causing-post-back – VDWWD Oct 10 '16 at 14:11

1 Answers1

0

you can try this

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

            }
        })
Sukhvindra Singh
  • 200
  • 2
  • 14