Nel

Nel

  • NA
  • 716
  • 1m

Problem with updating the textboxes in updatepanel

May 15 2014 2:17 PM
 

Hi,

I have several textBoxes which should be updated every several sec. I have a timer in the updatepanel as well and a label showing the refreshing time.

The label is updated, but not the textboxes.

Here is my code:

the aspx code

 

<asp:Button ID="Button3" runat="server" Text="Continuous" OnClick="Button3_Click" />
&nbsp;&nbsp;
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
            </Triggers>
            
            <ContentTemplate>
                <asp:Label ID="Label14" runat="server" Font-Names="Aharoni" ForeColor="#003366" Text="V/C"></asp:Label>
                <asp:TextBox ID="VCBox" runat="server" Width="84px"></asp:TextBox>
                <asp:Timer ID="Timer1" runat="server" Interval="5000" OnTick="Timer1_Tick" Enabled="False"> 
                </asp:Timer>
                <asp:Label ID="Label16" runat="server" ForeColor="#009999"></asp:Label>
                <br />
                <asp:Label ID="Label17" runat="server" BackColor="#009999"></asp:Label>
                <br />
                <asp:Label ID="Label9" runat="server" Font-Names="Aharoni" ForeColor="#003366" Text="Passing within # of cycles"></asp:Label>
                <table class="auto-style1">
                    <tr>
                        <td class="auto-style3">
                            <asp:Label ID="Label18" runat="server" ForeColor="#006666" Text="&lt;1"></asp:Label>
                            <br />
                            <asp:TextBox ID="c1" runat="server" Width="62px" style="text-align: center"></asp:TextBox>
                        </td>
                        <td class="auto-style3">&nbsp;<asp:Label ID="Label19" runat="server" ForeColor="#006666" Text="&lt;2"></asp:Label>
                            <br />
                            <asp:TextBox ID="c2" runat="server" Width="62px"></asp:TextBox>
                            &nbsp;&nbsp;&nbsp;</td>
                        <td class="auto-style3">
                            <asp:Label ID="Label20" runat="server" ForeColor="#006666" Text="&lt;3"></asp:Label>
                            <br />
                            <asp:TextBox ID="c3" runat="server" Width="62px"></asp:TextBox>
                            &nbsp;&nbsp;</td>
                        <td class="auto-style3">
                            <asp:Label ID="Label21" runat="server" ForeColor="#006666" Text="&lt;4"></asp:Label>
                            <br />
                            <asp:TextBox ID="c4" runat="server" Width="62px"></asp:TextBox>
                        </td>
                    </tr>
                </table>
                <asp:Label ID="Label10" runat="server" Font-Names="Aharoni" ForeColor="#003366" Text="Level of Service"></asp:Label>
                <table class="auto-style1">
                    <tr>
                        <td style="text-align: center" class="auto-style2">
                            <asp:Label ID="Label22" runat="server" ForeColor="#006666" Text="A"></asp:Label>
                            <br />
                            <asp:TextBox ID="losA" runat="server" style="margin-top: 0px" Width="62px"></asp:TextBox>
                        </td>
                        <td class="auto-style2">
                            <asp:Label ID="Label23" runat="server" ForeColor="#006666" Text="B"></asp:Label>
                            <br />
                            <asp:TextBox ID="losB" runat="server" style="text-align: center" Width="62px"></asp:TextBox>
                        </td>
                        <td class="auto-style2">
                            <asp:Label ID="Label24" runat="server" ForeColor="#006666" Text="C"></asp:Label>
                            <br />
                            <asp:TextBox ID="losC" runat="server" style="text-align: center" Width="62px"></asp:TextBox>
                        </td>
                        <td class="auto-style2">
                            <asp:Label ID="Label25" runat="server" ForeColor="#006666" Text="D"></asp:Label>
                            <br />
                            <asp:TextBox ID="losD" runat="server" style="text-align: center" Width="62px"></asp:TextBox>
                        </td>
                        <td class="auto-style2">
                            <asp:Label ID="Label26" runat="server" ForeColor="#006666" Text="E"></asp:Label>
                            <br />
                            <asp:TextBox ID="losE" runat="server" style="text-align: center" Width="62px"></asp:TextBox>
                        </td>
                        <td class="auto-style2">
                            <asp:Label ID="Label27" runat="server" ForeColor="#006666" Text="F"></asp:Label>
                            <br />
                            <asp:TextBox ID="losF" runat="server" style="text-align: center" Width="62px"></asp:TextBox>
                        </td>
                    </tr>
                </table>
            </ContentTemplate>
        </asp:UpdatePanel>

and the aspx.cs code:

  protected void Button3_Click(object sender, EventArgs e)
        {
            this.Counter1 = 0;
       
            Timer1.Enabled=true;
        }

        protected void Timer1_Tick(object sender, EventArgs e)
        {
            Label16.Text="Current time: " +
DateTime.Now.ToLongTimeString();

           // ReadList();
            Session["2"] = Session["sectionList"];
           
            var line = reader.ReadLine();
            var values = line.Split(',');
            List<String> sectionList2 = (List<String>)Session["sectionList"];
            Label17.Text = sectionList2[0];


            if (this.Counter1 < sectionList2.Count - 11)
            {
             
                VCBox.Text = sectionList2[this.Counter1].Remove(sectionList2[this.Counter1].Length - 1);
                c1.Text = sectionList2[this.Counter1 + 1].Remove(sectionList2[this.Counter1 + 1].Length - 1);
                c2.Text = sectionList2[this.Counter1 + 2].Remove(sectionList2[this.Counter1 + 2].Length - 1);
                c3.Text = sectionList2[this.Counter1 + 3].Remove(sectionList2[this.Counter1 + 3].Length - 1);
                c4.Text = sectionList2[this.Counter1 + 4].Remove(sectionList2[this.Counter1 + 4].Length - 1);
                losA.Text = sectionList2[this.Counter1 + 5].Remove(sectionList2[this.Counter1 + 5].Length - 1);
                losB.Text = sectionList2[this.Counter1 + 6].Remove(sectionList2[this.Counter1 + 6].Length - 1);
                losC.Text = sectionList2[this.Counter1 + 7].Remove(sectionList2[this.Counter1 + 7].Length - 1);
                losD.Text = sectionList2[this.Counter1 + 8].Remove(sectionList2[this.Counter1 + 8].Length - 1);
                losE.Text = sectionList2[this.Counter1 + 9].Remove(sectionList2[this.Counter1 + 9].Length - 1);
                losF.Text = sectionList2[this.Counter1 + 10].Remove(sectionList2[this.Counter1 + 10].Length - 1);
              
                this.Counter1 = this.Counter1 + 11;
                Label17.Text=Convert.ToString(this.Counter1);
            }
            else
            { this.Counter1 = 0; }
        }

Can anybody help me what to do in order the text boxes to be refreshed/updated every 5 seconds with data from a file?

Thanks





Answers (3)