I am looking for a possibility to update a button BackColor on Timer Tick. Every Tick there is an Dataimport from an external Source. If there is an Port "active" the Button should be GREEN, otherwise it should be RED.
The procedure work on Button click and separately in a Windows Application. There is an Time Update in the Code and it works, too.
On Timer Tick the C# Code takes the result from
res = dc.readBytes
and calculates the separeted Bits. If the result on Bit Position 6 is 1 it should be GREEN, outherwise RED.
Here is the ASP Code:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentSection" runat="server">
<form id="form2" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" AsyncPostBackTimeout="45">
</asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="2000">
</asp:Timer>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" RenderMode="Inline" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Label ID="Label2" runat="server">State</asp:Label>
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Panel ID="Panel1" runat="server">
<asp:Button ID="ButtonLBuero" runat="server" Height="120px" OnClick="ButtonLBuero_Click" Text="Licht Büro" Width="120px" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</asp:Panel>
</form>
</asp:Content>
Here the C# Code:
protected void Timer1_Tick(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToLongTimeString();
Label3.Text = Convert.ToString(Connection);
if (Connection)
{
res = dc.readBytes(libnodave.daveOutputs, 0, 0, 1, null);
if (res == 0)
{
byte outputByte = Convert.ToByte(dc.getU8());
if (IsBitSet(outputByte, 6))
{
Label2.BackColor = Color.Lime;
}
else
{
Label2.BackColor = Color.Red;
}
}
}
}
I think there is an error in the UpdatePanel Settings cause the skripts running on ist own.