2016-10-10 7 views
1

텍스트 상자의 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로 변경됩니다. 텍스트 상자에 텍스트를 입력하면 labelKoreaDivisi.text가 555로 변경됩니다. 하지만 labelKodeDivisi는 차가 아닙니다. nge. 내가 버튼을 butLogout

+0

이 http://stackoverflow.com/questions/4209903/asp-net-page-enter-key-causing-post-back 참조 시도 할 수 변경 – VDWWD

답변

0

을 쳤을 때 labelKodeDivisi 만이

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

      } 
     })