views:

807

answers:

3

Sometimes my ajax request is so fast that the user does not realize a ajax call was made. So I would like to force the UpdateProgress control to display for a minimum about of time, even if the ajax request has finsihed.

For example:

John browses the site and the ajax call takes 2 seconds to complete. I only want the UpdateProgress control to display for those 2 seconds.

Mary also browses the site but the ajax call takes > 0.5 seconds. So I want to display the UpdateProgress control for at least 1 full second.

Does anybody have any ideas on how to do this?

Edit

I have discovered that the AjaxLoadingPanel control offered by Telerik has this ability. It has a property called MinDisplayTime that does this very thing. It would be nice to know how to do this using the standard (Free) asp.net ajax controls.

Thanks

A: 
protected void Button1_Click(object sender, EventArgs e)
{
    System.Threading.Thread.Sleep(3000);
    Label1.Text = DateTime.Now.ToString();
}

http://www.asp.net/Ajax/Documentation/Live/tutorials/ProgrammingUpdateProgress.aspx

lod3n
Hi – The problem with this solution is that I would be adding an additional 3 seconds even if the Ajax call already took 2 seconds to execute. I only want to display the UpdateProgress control for a longer period *IF* the Ajax call took less than a certain amount of time.
Douglas
+1  A: 

I had the same problem working on an intranet site where the UpdatePanel contents changed so quickly that I couldn't tell if an update had happened without debugging, or checking the database.

The way I tackled this problem was to let the UpdatePanel do its thing as before, but use an UpdatePanelAnimationExtender to briefly flash a change of background colour, for example, before fading back to normal, giving the user the impression that an action has happened. If this happens quickly, say 0.3 of a second, and an appropriate 'action' colour is chosen, this can be very effective.

<ajaxToolkit:UpdatePanelAnimationExtender ID="myUpdatePanelExtender" runat="server" TargetControlID="myUpdatePanel">
     <Animations>
        <OnUpdating> ... </OnUpdating>
        <OnUpdated> ... </OnUpdated>
    </Animations>
</ajaxToolkit:UpdatePanelAnimationExtender>

You'll need to get the AJAX Control Toolkit, but if you're doing Asp.Net AJAX work, you'll be better off having it, if you don't already.

For what to place within the <OnUpdating> tag etc., see the Asp.Net Ajax Control Toolkit site page 'Using Animations'.

Rafe Lavelle
+1 Had not thought of using the UpdatePanelAnimationExtender before. Although it does not solve the particular problem described above, it provides another option in how I notify the user somthing has happend.
Douglas
You're right of course: it's more of a sideways solution to your problem. But it does have other advantages, such as: if there are several small update regions on the page that get affected by some button, or control, they may not be noticed by the user if the page is busy. A small burst of colour, fading after 0.5 sec, alerts them to any state changes on the page
Rafe Lavelle
A: 

you could work around the latter by keeping track of the time your server side code takes to execute (or perhaps even better by measuring the ajax execution time, but that's more tricky)

the idea is this

long startTime = System.DateTime.Now.Ticks;
//this process can take some time, especially when executed for the first time
//it gets data and binds it to a control
FetchData();
//if this takes not enough time, add an extra second to allow the UpdateProgress to display
if (TimeSpan.FromTicks(DateTime.Now.Ticks - startTime).TotalSeconds < 1)
            System.Threading.Thread.Sleep(1000);
dc2009