UPDATEPANEL DOES NOT UPDATE

Takeshi Okada

Total Post:89

Points:629
Posted by  Takeshi Okada
 1165  View(s)
Ratings:
Rate this:

I have an asp.net website which contains a Thread that fetches some data from a WCF service. That thread runs in an infinite loop waiting each run for 1 second. Now I would like to show the stuff it got from the WCF service in a label. I added that label to an UpdatePanel and invoked the .Update() method. I don't get any exceptions, however, the label does not update at all. Here is my code (simplified):

t = new Thread(new ThreadStart(() =>
{
   while (true)
   {
      Label1.Text = GetFromWCF() + " " + DateTime.Now.ToString();
      updatePanel.Update();
      Thread.Sleep(1000);
   }
}
));
t.IsBackground = true;
t.Start();

This code is in the OnInit Method of the page. The updatePanel looks like this:

<asp:ScriptManager runat="server" ID="scriptManager" EnablePartialRendering="true"/>
<asp:UpdatePanel runat="server" ID="updatePanel" UpdateMode="Conditional">
   <ContentTemplate>
      <asp:Label ID="Label1" runat="server" />
   </ContentTemplate>
</asp:UpdatePanel>

Am I missing anything? Maybe I should also inform you that I am very new to asp.net.

  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: UpdatePanel does not update

    Hi takeshi, 

    <asp:UpdatePanel runat="server"ID="update" UpdateMode="Conditional">
         <ContentTemplate>
             <asp:Label runat="server" ID="uiTime" />
             <asp:Button runat="server" ID="uiInternalButton" Text="Click" />
         </ContentTemplate>
         <Triggers>         <asp:AsyncPostBackTrigger ControlID="uiAsynch" EventName="click" />         <asp:PostBackTrigger ControlID="uiInternalButton" />
         </Triggers>
    </asp:UpdatePanel>
    <asp:Button runat="server" ID="uiPostback" Text="Click" />

      Modified On Apr-05-2018 06:18:44 AM
  1. Pravesh Singh

    Post:412

    Points:2888
    Re: UpdatePanel does not update

    <asp:UpdatePanel runat="server" ID="update" UpdateMode="Conditional">
         <ContentTemplate>
             <asp:Label runat="server" ID="uiTime" />
             <asp:Button runat="server" ID="uiInternalButton" Text="Click" />
         </ContentTemplate>
         <Triggers>
             <asp:AsyncPostBackTrigger ControlID="uiAsynch" EventName="click" />
             <asp:PostBackTrigger ControlID="uiInternalButton" />
         </Triggers>
    </asp:UpdatePanel>
    <asp:Button runat="server" ID="uiPostback" Text="Click" />

      Modified On Apr-05-2018 06:18:09 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!