question:
There is a control on the webform. It is best for this control to access the database in real time. Once there are changes in the database, the data will be submitted to the client and the latest data will be displayed.
analyze:
Because the client needs to be updated, the front-end clock function of js must be used. The server has changed, and the client needs to refresh to update the data. How can I update the data without refreshing, or falsely refresh the page, that is, the client basically sees No refresh.
Solution: (please correct me if there are any mistakes, my level is limited, thank you)
There are two main solutions: real-time and polling
Real-time: Trigger by adding a trigger in the database, and then writing a file in the server to use as a semaphore. I think this technology is too complicated for this problem, so I have not continued to study it. Friends who are interested can go to MSDN to see it, but it can indeed update data in real time, which is most effective for real-time conversations.
Polling: 1. Use xmlhttp no refresh method. For this method, you can read the article written by others that I forwarded earlier, which has a detailed introduction. However, after testing it, I found that what is obtained from the server is the HTML code of the entire page. You need to get the control content you need from it, and repeat it. The configuration is still too complicated and not necessarily efficient.
2. Use the HTML framework to complete it, which is the method I mainly write. This method is simple and easy to implement. I think it is very useful for situations where only small data is dynamically displayed.
Detailed introduction: Write iframe src="../test/WebForm2.aspx" in the place where the HTML needs to be updated. Src is the page to be connected, and then adjust the size of the frame and scroll bars as needed.
Create a new page WebForm2.aspx as the framed connection page. Put the controls that need to be updated in real time in this page, and then in the Page_Load event
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Place the code to get database updates here and associate it with the control End Sub
Then add meta HTTP-EQUIV="Refresh" content="1" URL="/test/WebForm2.aspx" to the html
It means that this page will be automatically refreshed every 1 second (you can also add a foreground clock such as window.setInterval(function,1000) according to the actual situation), so that the result is completed. After the first page is started, the second page will not be interrupted. It refreshes after a while, but the client feels the same as if it is not refreshed.