Bootstrap alert message from Server Side in ASP.Net

on Nov 07, 2016 01:55 AM


I want to show Bootstrap alerts from Codebehind in

After every CRUD operation i want to display bootstrap alert message.

The same which is our forum shows after posting que or any reply.

The message popup automatically dismissed.

Download FREE API for Word, Excel and PDF in ASP.Net: Download
on Nov 09, 2016 08:29 PM


Thanx for your reply!!!!

I found exact solution on below link:

 <html xmlns="">
<head id="Head1" runat="server">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="">
    <script src=""></script>
    <script src=""></script>

    <style type="text/css">
        .messagealert {
            width: 100%;
            position: fixed;
            z-index: 100000;
            padding: 0;
            font-size: 15px;
    <script type="text/javascript">
        function ShowMessage(message, messagetype) {
            var cssclass;
            switch (messagetype) {
                case 'Success':
                    cssclass = 'alert-success'
                case 'Error':
                    cssclass = 'alert-danger'
                case 'Warning':
                    cssclass = 'alert-warning'
                    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><strong>' + messagetype + '!</strong> <span>' + message + '</span></div>');
    <form id="form1" runat="server">
            <div class="messagealert" id="alert_container">

             <div style="margin-top: 100px; text-align:center;">
            <asp:Button ID="btnSuccess" runat="server" Text="Submit" CssClass="btn btn-success"
                OnClick="btnSuccess_Click" />
            <asp:Button ID="btnDanger" runat="server" Text="Danger" CssClass="btn btn-danger"
                OnClick="btnDanger_Click" />
            <asp:Button ID="btnWarning" runat="server" Text="Warning" CssClass="btn btn-warning"
                OnClick="btnWarning_Click" />
            <asp:Button ID="btnInfo" runat="server" Text="Info" CssClass="btn btn-info"
                OnClick="btnInfo_Click" />


 public enum MessageType { Success, Error, Info, Warning };
    protected void Page_Load(object sender, EventArgs e)
    protected void ShowMessage(string Message, MessageType type)
        ScriptManager.RegisterStartupScript(this, this.GetType(), System.Guid.NewGuid().ToString(), "ShowMessage('" + Message + "','" + type + "');", true);
    protected void btnSuccess_Click(object sender, EventArgs e)
        ShowMessage("Record submitted successfully", MessageType.Success);
    protected void btnDanger_Click(object sender, EventArgs e)
        ShowMessage("A problem has occurred while submitting data", MessageType.Error);
    protected void btnWarning_Click(object sender, EventArgs e)
        ShowMessage("There was a problem with your internet connection", MessageType.Warning);
    protected void btnInfo_Click(object sender, EventArgs e)
        ShowMessage("Please verify your data before submitting", MessageType.Info);