我有按钮数组,每个边框颜色都表示某种状态(蓝色=活动按钮;绿色=普通按钮,红色=“火”)。每个按钮代表硬件上的一个传感器。
按钮位于某些 UpdatePanel 中,其中 Timer 设置为1500 毫秒刷新。当计时器超时并被称为 Tick 事件时,页面加载事件被调用,我将颜色设置为按钮,因此着火的按钮设置为红色,正常的按钮设置为绿色,活动的按钮设置为蓝色。一切都很好,直到我单击某个调用单击事件的按钮,其中单击的按钮边框变为蓝色。我认为现在调用 Tick 事件时,这个单击的按钮现在应该失去蓝色边框颜色,并且它设置为默认绿色。但它保持蓝色,即使我把它放在火上(所以在下一个 Tick 事件之后它应该是红色的)它保持蓝色。有人可以帮助解决这个问题吗?
protected void Page_Load(object sender, EventArgs e)
{
//Here is condition which checks if is exist Session['ActiveSensor']
if (Session["ActiveSensor"] == null)
{
Session.Add("ActiveSensor", "A1");
Session.Add("LastActiveSensorIndex", "0");
}
//==================================================================
Sensors = new SensorNetwork();
sensor_buttons = new Button[Sensors.SensorNet.Length];
int i = 0;
foreach (Sensor sensor in Sensors.SensorNet)
{
sensor_buttons[i] = new Button();
sensor_buttons[i].ID = Convert.ToString(i);
sensor_buttons[i].BackColor = sensor.Temperature.TemperatureColor;
sensor_buttons[i].Text = Math.Round(sensor.Temperature.CelsiusTemperature, 2).ToString() + "°C";
sensor_buttons[i].Click += new EventHandler(sensor_Click);
sensor_buttons[i].BorderWidth=2;
if (sensor.Valid == false)
{
sensor_buttons[i].Enabled = false;
}
else {
sensor_buttons[i].Enabled = true;
}
if (sensor.Fire == true)
{
sensor_buttons[i].BorderColor = System.Drawing.Color.DarkRed;
}
else {
sensor_buttons[i].BorderColor = System.Drawing.Color.ForestGreen;
}
if (sensor.SensorID == Session["ActiveSensor"].ToString() && sensor.Fire==false) {
sensor_buttons[i].BorderColor = System.Drawing.Color.LightSkyBlue;
Session.Add("LastActiveSensorIndex", i.ToString());
}
UpdatePanel2.ContentTemplateContainer.Controls.Add(sensor_buttons[i]);
i++;
}
}
protected void sensor_Click(object sender, EventArgs e)
{
var ClickedButton =(Button)sender;
Sensor NewSensor=Sensors.SensorNet[Convert.ToInt32(ClickedButton.ID)];
ClickedButton.BorderColor = System.Drawing.Color.LightSkyBlue; //This button stays blue even if the Tick is called
}