How do I time a modal pop up?

2019-08-27 18:49发布

I have a function that does some database update in asp.net. I'd like a modal popup to show a "success" message for just 5 seconds after my function has been called. In this case, the modal popup would not be triggered by any "TargetControl" but would show up for just 5 seconds once the function is done.

Thanks

2条回答
该账号已被封号
2楼-- · 2019-08-27 19:19

You have to manually call the show method on the panel like:

var pnl = $find("<%= modal.ClientID");
pnl.show();

So you can use window.setTimeout to call this:

window.setTimeout(function() { /* code */ }, 5000);

But it can't just happen very easily.

HTH.

查看更多
放我归山
3楼-- · 2019-08-27 19:25

You can't close standard javascript modal dialogs (alert, confirm,..) after a timeout. Only manual close works with them.

But, you can use jquery/UI dialog:

// timeOut in ms
function showMessageWithTiemout(message, timeOut){

    // show dialog
    var successDialog = $('<div>'+message+'</div>').dialog({modal: true});  

    //close it after 5 seconds
    setTimeout(function(){ successDialog.dialog('close'); }, timeOut);

}

//usage:
showMessageWithTiemout('success!', 5000);
查看更多
登录 后发表回答