0

I have an ASP.NET page that displays a value which changes every second. Much like an example where time would be displayed and the time runs automatically.

For example, I have a method:

private void GetMethod()
{
    lblValue.Text = Convert.ToString(value1);
}

I need that value to change when it changes on the database, which is in intervals of seconds.

TylerH
  • 20,799
  • 66
  • 75
  • 101
fl13
  • 57
  • 1
  • 1
  • 12
  • You could try SignalR, with which it is possible to trigger a client update from the server. – CShark Apr 08 '20 at 10:03
  • the simplest and easy solution is a timer. – Pankaj Rawat Apr 08 '20 at 10:12
  • Duplicate of [How do I use updatePanel in asp.net without refreshing all page?](https://stackoverflow.com/questions/10929644/how-do-i-use-updatepanel-in-asp-net-without-refreshing-all-page) – TylerH Apr 08 '20 at 14:28
  • See also https://stackoverflow.com/questions/25575836/label-text-refresh-every-second ; https://stackoverflow.com/questions/10040828/how-can-i-change-the-text-of-a-texbox-in-every-second ; https://stackoverflow.com/questions/3880306/how-to-refresh-the-asp-net-label-every-second-automatically-using-java-script-in ; https://stackoverflow.com/questions/1740950/how-to-update-every-second-from-db – TylerH Apr 08 '20 at 14:30

2 Answers2

1

The right answer depends on what it is that's changing. You say 'constantly', I would assume you mean when some 'state' changes on the server. In which case, the SignalR suggestion is spot on since it will take care of most of the other methods that would be suggested to you implicitly (polling, sockets connection etc.).

But - if you mean 'constantly' as in every 1 second something changes regardless of what's happened on the server - a 'push' implementation would be excessive. Have the client do something regularly with setInterval() https://www.w3schools.com/jsref/met_win_setinterval.asp

JᴀʏMᴇᴇ
  • 218
  • 2
  • 15
0

A suggestion would be to look into SignalR It lets you update data in real-time fashion.