解決BarCode掃描因畫面Button導致畫面送出問題

解決BarCode掃描因畫面Button導致畫面送出問題

小喵最近開發畫面,須要讓使用者使用BarCode讀取資料在畫面輸入,為了讓使用者方便,小喵希望能夠在掃完機種後,游標自動的停留在數量上,於是小喵準備了以下的畫面,並且準備一段JavaScript來處理游標的問題

 

<head runat="server">
    <title>未命名頁面</title>
    <script language="jscript" type="text/jscript">
        function ItmKeyDown(OrgItemId,TargetItemId)
        {
            var orgItm = window.document.getElementById(OrgItemId);
            var targetItm = window.document.getElementById(TargetItemId);
            if(window.event.keyCode==13)
            {
                targetItm.focus();
                return false;
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server"> 
    <div>
        機種:<asp:TextBox ID="txtModel" runat="server"></asp:TextBox><br />
        數量:<asp:TextBox ID="txtQty" runat="server"></asp:TextBox><br />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>

接著小喵在PageLoad事件中,準備好把Clinet端的Function與txtModel的Client端onKeyDown事件結合

Me.txtModel.Attributes.Add("onkeydown", kdScript)

 

 


以下是簽名:


Microsoft MVP
Visual Studio and Development Technologies
(2005~2019/6) 
topcat
Blog:http://www.dotblogs.com.tw/topcat