Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap modal popup c# codebehind

i am using bootstrap in my c# asp.net project and i want to show to show the modal popup from code behind.

in my page header i have a javascript function as follows:

function LoginFail() {
        $('#windowTitleDialog').modal('show');
    }

and on the click of my button i am calling the javascript as follows

ScriptManager.RegisterClientScriptBlock(this, typeof(System.Web.UI.Page), "LoginFail", "LoginFail();", true);

this does not show the modal popup. however, if i use something like alert('login failed'), it works fine.

can anybody please help with this?

like image 982
user1144596 Avatar asked Mar 28 '13 17:03

user1144596


People also ask

How do I use bootstrap modal popup?

To trigger the modal window, you need to use a button or a link. Then include the two data-* attributes: data-toggle="modal" opens the modal window. data-target="#myModal" points to the id of the modal.

How do I get the modal pop up in the center of the screen?

Example 1: First, we will design modal content for the sign-up then by using CSS we will align that modal centered(vertically). Using the vertical-align property, the vertical-align property sets the vertical alignment of an element.

How do I stop bootstrap modal pop up?

Clicking on the modal “backdrop” will automatically close the modal. Bootstrap only supports one modal window at a time.


1 Answers

By default Bootstrap javascript files are included just before the closing body tag

    <script src="vendors/jquery-1.9.1.min.js"></script>
    <script src="bootstrap/js/bootstrap.min.js"></script>
    <script src="vendors/easypiechart/jquery.easy-pie-chart.js"></script>
    <script src="assets/scripts.js"></script>
 </body>

I took these javascript files into the head section right before the body tag and I wrote a small function to call the modal popup:

<script src="vendors/jquery-1.9.1.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="vendors/easypiechart/jquery.easy-pie-chart.js"></script>
<script src="assets/scripts.js"></script>

<script type="text/javascript">
function openModal() {
    $('#myModal').modal('show');
}
</script>
</head>
<body>

then I could call the modal popup from code-behind with the following:

protected void lbEdit_Click(object sender, EventArgs e) {   
  ScriptManager.RegisterStartupScript(this,this.GetType(),"Pop", "openModal();", true);
}
like image 129
wallace740 Avatar answered Oct 04 '22 01:10

wallace740