C# 引导模式中的 ASP.NET 按钮不会触发单击事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17380287/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ASP.NET button inside bootstrap modal not triggering click event
提问by skhurams
Hi im working in bootstrap modal in my asp.net site, modal is working fine but the button btnSaveImage inside modal footer is not firing click event, i also have a masterpage and the form tag is in it, here is my code
嗨,我在我的 asp.net 站点的引导模式中工作,模式工作正常,但模式页脚中的按钮 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>
采纳答案by bjvilory
You can use the ASP Button like in your example
您可以像在示例中一样使用 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>
just try the UseSubmitBehavior="false"like said skhuramsand combine it with the data-dismiss="modal"
就像说skhurams一样尝试UseSubmitBehavior="false"并将其与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>
this will close the modal and trigger the postback
这将关闭模态并触发回发
回答by Fahad
I'd like to add another point here. I faced this issue because my final rendered modal dialogs were placed outside the WebForms <form>tag, and using the UseSumbitBehavior="false"did not solve my problem. Moving the modal dialog divs inside the form solved the issue.
我想在这里补充一点。我遇到这个问题是因为我最终呈现的模态对话框被放置在 WebForms<form>标签之外,并且使用UseSumbitBehavior="false"没有解决我的问题。在表单内移动模态对话框 div 解决了这个问题。
$("div.modalForm").appendTo($("form:first"));

