3

I am working on a asp.net project. It is not a MVC project. I have a requirement to display status messages (save succesful, save failed etc) some where on the page. I am using bootstrap alerts to display the same. I am using the below code to display the alerts.

<div class = "row" style="margin:0 2px 0 2px" >
    <div class="col-md-12" id="AlertNotificationDiv" runat="server">
      <asp:Label id="AlertNotificationBox" runat="server"/>
    </div>
</div>

On the code behind file I am using the following code to set the alerts

if (!AlertNotificationDiv.Visible)
    AlertNotificationDiv.Visible = true;
if (!AlertNotificationBox.Visible)
    AlertNotificationBox.Visible = true;

AlertNotificationDiv.Attributes.Add("class", "col-md-12 col-xs-12 col-ms-12 alert alert-success alert-dismissable");
AlertNotificationBox.Text = "Some message comes here";

Is this fine or is there any better way to handle the scenario. The problems I am facing with this approach is. 1. I am not able to provide a functionality where in the alert closes in about 5 sec. With some code I was able to hide the the alert after a few seconds, but if there is any post back for any other action it is appearing again.

Can somebody tell me as to how I can make this alert go after a few seconds and it does not come again until I explicitly make the visibility to true.

Thanks in advance.

rednerus
  • 401
  • 2
  • 9
  • 21
  • 1
    for auto-close the alert, did you try http://stackoverflow.com/questions/7643308/how-to-automatically-close-alerts-using-twitter-bootstrap – Michael B. Aug 14 '14 at 02:11

1 Answers1

0

Add this code at beginning of page_load to reset the message

AlertNotificationDiv.Visible = false;
AlertNotificationBox.Text = "";

Then on some action where you need to display the alert, set to visible and text to the alert message

Don't see need for setting AlertNotificationBox.Visible, because it will be hidden and displayed with the container div.

Michael B.
  • 2,798
  • 1
  • 14
  • 18