Home > DeveloperSection > Forums > UpdatePanel does not update
Takeshi Okada
Takeshi Okada

Total Post:89

Points:629
Posted on    August-28-2014 2:00 AM

 ASP.Net
Ratings:


 2 Reply(s)
 722  View(s)
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.



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    August-28-2014 3:11 AM

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" />


Pravesh Singh

Total Post:411

Points:2881
Posted on    September-30-2014 1:13 AM

<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" />


Don't want to miss updates? Please click the below button!

Follow MindStick