引导模式内的ASP.NET按钮不会触发click事件

时间:2013-06-29 12:41:55

标签: c# asp.net twitter-bootstrap modal-dialog buttonclick

你好我在我的asp.net网站上的bootstrap模式工作,模态工作正常但模式页脚内的按钮btnSaveImage没有触发点击事件,我也有一个母版页和表格标签在里面,这里是我的代码

 <a href="#dvUpload" data-toggle="modal">
   <asp:Button runat="server" ID="lnkUploadPics" CssClass=" btn-large Greengradiant"
                                    Width="100%" Text="Upload pictures"></asp:Button>
   </a>
   <div id="dvUpload" 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="myModalLabel">
             Upload Image</h3>
           </div>
             <div class="modal-body">
            <div class="row-fluid" style="padding-left: 10px; padding-right: 10px; padding-bottom: 20px;"> 
<div id="Upload" class="span6">
        <asp:FileUpload ID="fuImage" runat="server" />
       <img id="imgUPload" runat="server" src="" />
              </div>
             </div>
            </div>
          <div class="modal-footer">
           <button data-dismiss="modal" class="btn  btn-large"> Close</button>
           <asp:Button runat="server" ID="btnSaveImage" Text="Save Image" CssClass="Greengradiant btn-large" OnClick="btnSaveImage_Click" />
            </div>
         </div>

2 个答案:

答案 0 :(得分:32)

您可以像示例中那样使用ASP按钮

<div class="modal-footer">
   <button data-dismiss="modal" class="btn  btn-large"> Close</button>
   <asp:Button runat="server" ID="btnSaveImage" Text="Save Image" CssClass="Greengradiant btn- large" OnClick="btnSaveImage_Click" />
</div>

尝试 UseSubmitBehavior =“false”,如 skhurams ,并将其与 data-dismiss =“modal”结合使用

<div class="modal-footer">
   <button data-dismiss="modal" class="btn  btn-large"> Close</button>
   <asp:Button runat="server" ID="btnSaveImage" Text="Save Image" CssClass="Greengradiant btn- large" OnClick="btnSaveImage_Click" UseSubmitBehavior="false" data-dismiss="modal" />
</div>

这将关闭模态并触发回发

答案 1 :(得分:0)

我想在这里补充一点。我遇到了这个问题,因为我最终的渲染模式对话框被放置在WebForms <form>标记之外,并且使用UseSumbitBehavior="false"不能解决我的问题。在表单中移动模式对话框div即可解决此问题。

$("div.modalForm").appendTo($("form:first"));