Good afternoon, I'm trying to apply location.reload
to the end of a messagebox after the .remove()
effect of 2 seconds but I'm not familiar with javascript
could someone help me with the code:
function ShowMessage(message, messagetype, icon) {
var cssclass;
switch (messagetype) {
case 'Success':
cssclass = 'alert-success'
break;
case 'Error':
cssclass = 'alert-danger'
break;
case 'Atenção':
cssclass = 'alert-warning'
break;
default:
cssclass = 'alert-info'
}
$('#alert_container').append(
'<div id="alert_div" style="margin: 0 0.5%; -webkit-box-shadow: 3px 4px 6px #999;" class="alert fade in ' + cssclass + '" ><a href="#" class="close" data-dismiss="alert" aria-label="close">×</a><label class="' + icon + '"></label><strong>' + messagetype + '!</strong> <span>' + message + '</span></div > ');
setTimeout(function() {
$("#alert_div").fadeTo(500, 0).slideDown(500, function() {
$("#alert_div").remove();
});
}, 2000); //<- aplicar aqui o refresh, ao desaparecer a mensagem
}
$(document).ready(function() {
ShowMessage(" Excluido com sucesso!", 'Success', "icon fa fa-check");
});
@import 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css';
@import 'https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css' .messagealert {
/*position: absolute;*/
left: 35%;
top: 15%;
width: 30%;
position: fixed;
z-index: 100000;
padding: 0;
font-size: 15px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script><scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<div class="messagealert" id="alert_container">
</div>
Code-behind C #:
public enum MessageType { Success, Error, Info, Warning };
Function:
public void ShowMessage(string Message, MessageType type, string icon)
{
ScriptManager.RegisterStartupScript(this, this.GetType(),
System.Guid.NewGuid().ToString(),
"ShowMessage('" + Message + "','" + type + "', '" + icon + "');", true);
}
Calling the function:
ShowMessage(" Excluido com sucesso!", MessageType.Success, "icon fa fa-check");