asp.net 基于c#从SerialPort中读取数据,为什么显示不到页面上面,但可以得到数据库中。求解。

showEventHandler aa;
public void show(string a)
{
TextBox1.Text = a;
Label1.Text = a;
}
private void ReadPort(Object sender, SerialDataReceivedEventArgs e)
{

Thread.Sleep(500);
if (spReceive.IsOpen)
{
byte[] readBuffer = new byte[4];
try
{
spReceive.Read(readBuffer, 0, 4);
string s100 = ByteArrayToHexString(readBuffer);
aa = new UpdateTextEventHandler(show);
aa(s100);
ReadInto(s100);

}

catch (TimeoutException) { }
}
else
{
TimeSpan waitTime = new TimeSpan(0, 0, 0, 0, 50);
Thread.Sleep(waitTime);
}

}

第1个回答  2012-04-06
public void show(string a)
{
TextBox1.Text = a;
Label1.Text = a;
}

不要把控件赋值,写在方法里
写到 load事件去
protected void Page_Load(object sender, EventArgs e)
{
this.TextBox1.Text = a;
this.Label1.Text = a;
}
相似回答
大家正在搜