ASP.NET: displaying state information while saving data to DB
I have an ASP.NET 2.0 web application. I want to show a progress bar when the user saves some data (example: Editing a profile). I've already used jQuery in my application for some client side side effects. How can i do this? any jQuery trusted stuff to be used along with ASP.NET? thanks in advance
a source to share
Do you want to show actual progress or just a busy indicator during an action? If the former, you will need a mechanism to record the save progress in the session and a method to check the progress status via AJAX. You have to submit the form via AJAX and then periodically call the validator method to receive progress reports and update any client-side indicator (usually switching from one to another from a series of canned images or increasing the width of the filled "bar")). It is, of course, difficult.
If you want to do the latter, just show the animated GIF to be displayed during a form submission via AJAX from jQuery using the beforeSend callback, then hide the indicator using the full ajax method handler.
$('form').ajax( {
url: '/updateprofile.aspx',
type: 'POST',
data: function() { return $('form').serialize(); },
beforeSend: function() { $('#indicator').show(); },
complete: function() { $('#indicator').hide(); },
success: function(data,status) { alert('Update complete'); }
});
The above code will reside in a function called from any handler that invokes the view or is bound to the form's submit event - although you will also need to prevent the default action.
a source to share
An alternative to displaying a meaningful progress bar is to display an animated gif while the data is being saved, for example. the rotating daisy pattern used in Firefox.
This shows the user that something is happening and is usually well received.
Progress bars that show% complete don't make sense anyway unless they really have an idea of how long the first 50% will take versus the last "50%". Other indicators of progress are more meaningful, for example. those that show the increment in the number of records, etc.
a source to share