Bootstrap message, apply Location.Reload upon termination message

Asked

Viewed 436 times

0

Good afternoon, I’m trying to apply location.reload at the end of a messagebox after effect .remove() 2 seconds but I’m not familiar with the javascript someone could 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>
<script src="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");
  • include html and css

  • @Leandroangelo Incluídos

  • your example does not open the message

  • @Leandroangelo apologies, I call the message via code-Behind c#

2 answers

1


  • at the end of the 2 seconds of the message the page is in a loop updating. It has to update only once

  • 1

    How are you calling your function ? After saving information in the bank ? Do a redirect on to see: window.location.href = "coloque o endereço aqui";

  • yes, after executing a delete, call the message via code-Behind C#, the message appears saying it was deleted after 2 seconds it disappears... when it disappears need to refresh the page

  • redirected window.location.href = "put the address here"; good thanks!

  • I had answered so at first, there when I read Reload I edited the answer :D

0

I made a redirect as wmsouza comment, worked as wanted thank you!

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.