codeBoy
codeBoy

Reputation: 533

Dynamic Text in Bootstrap Alert

I have a bootstrap alert like so :

<div class="alert alert-danger">
    <a href="#" class="close" data-dismiss="alert">&times;</a>
     First Error
</div>

My problem is I want to be able to change this text dynamically in my code behind, c#. Ideally, I would like to have multiple bullet pointed error messages in one alert like the image below:

enter image description here

Can anyone provide me with any ideas of how to achieve this?

Upvotes: 1

Views: 4065

Answers (2)

user4843530
user4843530

Reputation:

In your html, have this

<div id="BootstrapErrorMessage" runat="server">
</div>

and in your code, do this

....
MyErrorString += "<li>Bad Password</li>";
....
MyErrorString += "<li>Invalid Date</li>";
....
if (!MyErrorString.isNullOrEmpty()) {
    BootstrapErrorMessage.InnerHtml += "<a href=\"#\" class=\"close\" data-dismiss=\"alert\">&times;</a>" +
                                       "<ul>" + MyErrorString + "</ul>";
    BootstrapErrorMessage.Attributes["class"] = "alert alert-danger";
}

Upvotes: 1

Kram
Kram

Reputation: 526

You can download the error messages to the client when he request the model of your page(recommended solution). Or you can post your data to the server and get list of errors to show.

Your html code should be like this:

<div class="bs-example">
    <div class="alert alert-danger fade in">
        <ul>
            <li><strong>First</strong> Error </li>
            <li>Second Error</li>
        </ul>
    </div>
</div>

And each li element should be updated from server(One of the options you choose).

Upvotes: 0

Related Questions