Click here to Skip to main content
15,907,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
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.NET
<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:

C#
protected void Timer1_Tick(object sender, EventArgs e)
        {
            Label1.Text = DateTime.Now.ToLongTimeString();
            Label3.Text = Convert.ToString(Connection);
            //Label4.Text = 
            if (Connection)
            {
                res = dc.readBytes(libnodave.daveOutputs, 0, 0, 1, null);



                if (res == 0)
                {
                    //int output = dc.getU8();
                    byte outputByte = Convert.ToByte(dc.getU8());
                    //label5.Text = Convert.ToString(output);



                    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.
Posted
Comments
DamithSL 4-Jan-15 8:06am    
have you debug and check?

1 solution

As your button is not in the update panel so it won't work.So i think put your button in the update panel then it would work.
 
Share this answer
 
Comments
Member 11274876 6-Jan-15 10:19am    
I am testing the Script by updating Label2.Backcolor. it is the sam elike the Button.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900