2011-06-18 60 views
0

網頁我有文本框和按鈕。按下後不需要按鈕上onClick事件輸入

我添加了onClick按鈕。

問題是,如果我點擊在文本框中輸入它也調用onClick事件按鈕。我明白爲什麼。

我的代碼是在這裏:

文本框是在視圖:

     <asp:View ID="BlView" runat="server"> 
          <p class="tabHead"> BLACK LIGHT LABEL DATA </p> 
          <table class="tab"> 
           <tr> 
            <td> 
             <asp:Label ID="Label1" runat="server" class="label" Text="BARCODE" /> 
            </td> 
            <td> 
             <asp:TextBox ID="bl_tb_barcode" runat="server" BorderWidth="1px" 
              class="textBox" Width="700"/> 
            </td> 
           </tr> 
          </table> 
        </asp:View> 

按鈕的代碼是在這裏:

 <div class="divPrinter"> 
     <asp:DropDownList runat="server" class="dropDownList" Width="250" Height="35" 
      ID="cbPrinters" style="margin-top:80px"/> 
     <asp:Button ID="btnPrint" runat="server" class="btnPrint" style="margin-top:80px" 
      Width="120" Height="35" Text="Print" onclick="BtnPrintClick" /> 
     </div> 

回答

2

我想你不希望Enter鍵有什麼作用?如果是這樣,這個標籤添加到您的文本框:

onKeyDown = "return (event.keyCode != 13)" 

所以它會是這樣:

<asp:TextBox ID="bl_tb_barcode" runat="server" BorderWidth="1px" 
    class="textBox" Width="700" onKeyDown="return (event.keyCode != 13)"/> 

作爲一個方面說明,onKeyDown是一個Javascript事件,所以它不會在執行服務器。該代碼將返回false,因此不會發生回傳。