简体   繁体   中英

How do I display a value that changing every second without doing a page refresh?

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.

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM