ASP.NET AJAX progress bar: updating from code?

I have an import function for an Excel spreadsheet in an application. Currently it uses the FileUpload control. I upload a file and then run an operation on this file. I want to inform the user about the operation and the percentage that will be done. I believe that I can take the total number of rows that I extracted from the Excel spreadsheet and divide constantly when I insert each record into the database and update the progress bar.

The problem is that I cannot find any solution that updates the progress bar from Behind code. I tried using Matt Bersett's solution .

It’s very nice to watch, but I don’t see it working from Behind code. Theoretically, I thought that inserting a value into the text box on the page, and setting onchange to the JavaScript function to set the percentage would work as a test, but even this did not give me the desired results.

Any suggestions on how to do this?

+5
source share
1 answer

, , FileUpload. , , ODBC ( ajax script).

, CSS ( : http://css-tricks.com/examples/ProgressBars/).

script ( -) , :

.asmx - :

[WebMethod]
public int GetStatus()
    {
        int progress = 0; // in percents
        // your server-side code here
        return progress;
    }

aspx - :

<asp:ScriptManager runat="server" ID="ScriptManager">
 <Services>
    <asp:ServiceReference Path="~/services/import.asmx" InlineScript="false" />
 </Services>
</asp:ScriptManager>

JavaScript ( , , setTimeout), JavaScript jQuery:

var tout, service;

function UpdateStatus() {
    if (tout != null)
         clearTimeout(tout);

    if (service == null)
         service = new namespace.here.serice_class_here();

    service.GetStatus(onSuccess, onFailure);    
}

function onSuccess(result) {
    // update the width of the progress with result (the integer value of the progress)
    progress_bar.style.width = percent + "%";        

    // call the method again
    tout = setTimeout("UpdateStatus()", 1000);
}

function onFailure(error) {
    alert(error.get_message());
}

JavaScript onSuccess ( 100%), .

, !

+1

All Articles