我有一个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;
}
}
当我运行程序时..该文本框甚至无法显示错误消息。 我尝试过
有人知道如何解决此问题吗?非常感谢