Simple implementation of Asp.net progress bar

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.