简体   繁体   中英

ASP.NET Button click event not firing in bootstrap modal

I'm using Bootstrap in my website. In that a registration modal pops up when a signup button is clicked. It has some fields and a register button and a close button. Their code is

<div id="myModalRegister" runat="server" class="modal hide fade" tabindex="-1"
 role="dialog" aria-labelledby="myModalLabel"
    aria-hidden="true">
    <div class="modal-header">
     <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
            ×</button>
        <h3 id="H1">
            Register</h3>
    </div>
    <div class="modal-body">

    <i class="icon-user"></i>Email ID</label>
        <input type="text" class="span3" id="txtRegEmail" runat="server" />
        <br />
    </div>

    <div class="modal-footer">
        <button class="btn btn-danger" data-dismiss="modal" aria-hidden="true">
            Close</button>
        <asp:Button ID="btRegister" runat="server" CssClass="btn btn-primary" 
            Text="Register" onclick="btRegister_Click" />
    </div>
</div>

The Sign up Button is

<li class="one"><a href="#myModalRegister" role="button" data-toggle="modal" >
       <i class="icon-user icon-white"></i> Sign Up</a></li>

When I click on the btRegister button the Click event is not firing. Can you help me??

After some Research I found out that the Modal Window is rendered outside the Form Tag. and that is why the Event is not firing. How can I resolve this ???

I think you have two options:

  1. put the button inside the tag (you don't need your modal to be outside of the form tag)
  2. use a javascript enabled button instead of a server side control

我今天遇到了同样的问题,发现我的按钮ID与表单中的另一个按钮相同,尝试检查你没有另一个具有相同ID的按钮,那么它会像BOSS一样工作!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM