tags:

views:

29

answers:

1

I want to delay blocking by 2 seconds while executing this code. How can I do that ? I tried setTimeout but it did not worked.

document.getElementById('<%=btnSave.ClientID%>').disabled=true;
document.getElementById('<%=btnSave.ClientID%>').value='Saving...';
$('#Block').block({message:'Please wait...',css: { border: '3px solid #a00' }}); 
+1  A: 

You're correct to use setTimeout() here, like this:

//block, what you currently have:
$('#Block').block({message:'Please wait...',css: { border: '3px solid #a00' }}); 

//unblock in 2000ms, or 2 seconds
setTimeout(function() { $('#Block').unblock(); }, 2000); 

If you're dealing with an UpdatePanel then I would look at the end_Request event, and actually unblock/reenable when the request finishes.

Nick Craver
Nick the unblock is inside endRequest of PageRequestManager. I set it over there but it won't work.
Popo
It is unblocking but just in a snap. I think there is some other problem maybe the script is broken.
Popo
@Popo - Is you block element inside the update panel? in that case it'll be getting replaced with the request.
Nick Craver
Nick, yeah the div is inside the update panel, source of problem=)
Popo
@Popo - Then you need to either move it outside the panel, or call `.block()` with a 0 fade-in time to get the illusion it never went away just before the `.unblock()`.
Nick Craver
thanks Nick you were spot on. The div inside update panel was the main problem.
Popo
Hi just a little question, how can I disable the button for 2 seconds also. $('#Block').block({message:'Please wait...',css: { border: '3px solid #a00' }}); document.getElementById('<%=btnSave.ClientID%>').disabled=true; document.getElementById('<%=btnSave.ClientID%>').value='Saving...';
Popo
button is inside update panel, div outside update panel
Popo