In the program, you need to use progress bars to intuitively reflect the progress of command execution. However, Asp.net does not have any special progress bar controls. I searched the internet and found that the implementation methods are complicated, I just made one by myself, which is actually very easy to implement. Later I thought about a method, which is added later.
Solution 1: Applicable to webform
Results:Figure:
The two-layer div is used to represent the total outer frame of the progress bar and the current progress. By continuously adjusting the DIV width of "processbar", the current progress is displayed.
<HTML xmlns = "http://www.w3.org/1999/xhtml">
Background code
Use clientscript. registerstartupscript registers a new JS script to the front-end code, but you need to pay attention to clientscript. registerstartupscript (clientscript. if the key in GetType (), key, STR) is the same, the expression only takes effect for the first time. To continuously refresh the progress bar on the page, we must constantly change the key value.
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim i As Int16 Dim str As String = "" For i = 0 To 100 str = "<script>" str += "set();" str = str + "</script>" ClientScript.RegisterStartupScript(ClientScript.GetType(), "set" & i, str) Next End Sub
Solution 2: UI code separation
Idea: implemented through intermediate files. Three files are required: front-end files,
Idea: the background program writes the running real-time status to the session. The intermediate file outputs the status of the current session. The foreground file reads the output of the intermediate file repeatedly, obtain the execution progress of the background program and display it to display the progress. This scheme will cause callback execution errors when jquery nested calls are used, and the specific code will be added later.