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
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);
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.
Related
onclick of a button creates a window, add to UI, I want to close this window using javascript ? please advice how to close this window using javascript after some timeout?
Button button= new Button("load Content",e->{
Window sub= new Window();
UI.getCurrent().addWindow(sub);
});
Try this:
setTimeout("window.close()", 5000);
// here 5000 ms refers to 5 seconds
I am using Telerik radscheduler when I move appointment then I want open a dialog box and after clicking yes or no, I want to go to OnAppointmentUpdate event.
function onAppointmentMoving(sender, eventArgs) {
debugger;
redgrd = sender;
eventArgs.set_cancel(true);
var appointment = eventArgs.get_appointment();
var confirmMessage = "Do you want to make this the patient's default Round?";
radconfirm(confirmMessage,
function (arg) {
debugger;
if (arg) {
//sender.updateAppointment(sender, eventArgs)
alert("ok");
}
else {
alert("Cancel");
}
})
}
I used the code in screen shot, but after eventArgs.set_cancel(true) I am not able to reach OnAppointmentUpdate event.
Calling eventArgs.set_cancel(true) means that you will cancel not only the AppointmentMoving event but also the flow. That's why the OnAppointmentUpdate event is not fired. Better try to call eventArgs.set_cancel(true) after you get the result from the confirm window.
I am developing web application. In that i want to open one popup using thickbox after 5 seconds when user comes to entry page.
Can any one give some idea how to do this?
You can use the setTimeout() from javascript with the command from the thickbox, something like:
// when dom is ready
$(document).ready(function() {
// set a timer thats run 5sec
setTimeout(function(){
// open the pop
var me = $('#ElementToOpen');
var t = "title"
var a = "openurl";
var g = false;
tb_show(t,a,g);
},5000);
});
I have a website with master page. I want to catch a user trying to close the browser/tab. When I try using onunload in the body tag, it fires not only when I try closing the browser, but also when I navigate to another page.
Any idea how to only catch the event of closing the browser?
You can't distinguish closing the browser from navigating to another page. In both cases the current page is unloaded.
update: maybe you can handle some cases with some jquery, i.e. whenever a link is clicked, set some flag to be able to distinguish it from closing the window or entering a new URL:
<body onunload="checkForClose()">
...
<script>
var _isNavigation = false;
$(document).ready(function () {
// whenever a link is clicked set _isNavigation to true
$('a').click(function () {
_isNavigation = true;
});
});
function checkForClose() {
// show an alert if _isNavigation is not set
if (!_isNavigation) alert("closing the browser (maybe)");
}
</script>
Short Explanation:
I have a script control that has the click event being handled in the script file. The Click handler pops up a confirm prompt and returns the prompt's value.
Problem:
IE sees the return False (Cancel is selected on the confirm box) and there is no postback. Firefox ignores this and fires the postback.
Solution?:
I read that if I were doing this the old fashion way, I would need to have:
onClick="return SomeMethod();"
In the markup. There hopefully is a way to do this with script controls?
Example:
Here's what I have in the script file:
//THIS IS THE METHOD CLICK CALLS
handleLnkDeleteButtonClick: function(e)
{
var confirmed = confirm('This will delete the current Message category and move all messages to the Oprhan cataegory. Continue?');
return confirmed;
},
initialize: function()
{
this._lnkDeleteButton = $get(this._lnkDeleteButtonID);
this._lnkDeleteButton.idpicker = this;
//HOOK BEGINS HERE
this._lnkDeleteButtonClick = Function.createDelegate(this, this.handleLnkDeleteButtonClick);
$addHandler(this._lnkDeleteButton, "click", this._lnkDeleteButtonClick);
//END HOOK HERE
NDI.WebControls.Client.PersonalMessageTypePicker.callBaseMethod(this, 'initialize');
},
dispose: function()
{
$removeHandler(this._lnkDeleteButton, "click", this._lnkDeleteButtonClick);
NDI.WebControls.Client.PersonalMessageTypePicker.callBaseMethod(this, 'dispose');
}
Ok so solved it myself after about way too much time trying to phrase things correctly for google. Turns out there is a method to call so that you don't have to worry about returning true or false.
handleLnkDeleteButtonClick: function(e)
{
var confirmed = confirm('This will delete the currery Message category and move all messages to the Oprhan cataegory. Allow?');
if (!confirmed)
{
e.preventDefault();
}
},
So instead of returning confirmed, I merely had to check it's value and call the e.preventDefault method to stop the click from firing.