Bootstrap message, apply location.reload at the end of message

0

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">&times;</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");
    
asked by anonymous 01.02.2018 / 19:54

2 answers

1

Add the code below to:

$("#alert_div").remove();
// Redireciona
window.location.href = "http://pt.stackoverflow.com";

There are several ways to redirect, see more on this question: How to redirect the user to another page in JavaScript / jQuery?

  

Reversing Editing

    
01.02.2018 / 23:23
0

I made a redirect according to wmsouza's comment, it worked as I wanted it to!

    setTimeout(function () {                
        $("#alert_div").fadeTo(500, 0).slideDown(500, function () {
            $("#alert_div").remove(); 
            window.location.href = "/Views/Default.aspx";
        });               
    }, 2000); //= 2 seconds
}
    
02.02.2018 / 00:37