这是我第一次使用此条形码扫描仪硬件。扫描完成后,该值将存储到textfile(记事本)中。我在输入条形码后自动清除文本框时遇到问题。我必须点击文本框再进行扫描。
public partial class Attendance : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSave_Click(object sender, EventArgs e)
{
string Filename = "C:/Users/Nor Asyraf Mohd No/Documents/TestFile.txt";
if (!File.Exists(Filename))
{
StreamWriter txtFile = File.CreateText(Filename);
txtFile.Close();
txtFile = File.AppendText(Filename);
txtFile.WriteLine(txtText.Text);
txtFile.Close();
}
else
File.AppendAllText(Filename, txtText.Text + Environment.NewLine);
txtText.Text = " ";
lblError.Text = "Employee ID is saved";
Response.AddHeader("REFRESH", "2;URL=Attendance.aspx");
}
protected void Button1_Click1(object sender, EventArgs e)
{
Response.Redirect("Default.aspx");
}
}