按键功能在文本框上不起作用

我有一个Web表单项目,我想在其中使用按键将数据插入文本框。

这是我的aspx文件

 <asp:Textbox runat ="server" id="Scan" style="width:1200px;height:100px;border:1px solid #000; background-color:white"></asp:Textbox>

aspx.cs文件

private void textbox1_KeyPress(object sender,System.Windows.Forms.KeyPressEventArgs e)
        {

            string strSql;
            string en ;
            en = desk;



            //if (e.KeyChar == Strings.Chr(13))
            if (e.KeyChar == (char)Keys.Enter)
            {

                string strDeskNo = (Scan.Text);//sepatutnya ada Trim(Scan.Text)
                strSql = "Insert into  ";// sql statement

                if (strDeskNo == "")
                {
                    Scan.Style.Add("color","red");
                    Scan.Text = "Please scan again ! ";



                    msgBoxOpen = true;
                    MessageBox.Show("There is no desk no entered! Please Scan again.","Warning",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                    msgBoxOpen = false;



                    Scan.Text = "";
                    Scan.Style.Add("background-color","white");
                    Scan.Focus();


                    return;
                }

                e.Handled = true;
}
}

当我运行程序时..该文本框甚至无法显示错误消息。 我尝试过

  1. https://www.codeproject.com/Questions/376421/Csharp-Keydown-or-keycode-not-working

  2. "KeyPress" event for WinForms textbox is missing?

有人知道如何解决此问题吗?非常感谢

gzdvd 回答:按键功能在文本框上不起作用

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3113351.html

大家都在问