您不能在JavaScript警报中使用asp:Button
,在asp.net中创建警报或模式对话框的最佳方法是创建您自己的并使其隐藏或在主页面中处于非活动状态并调用它当你需要它时。
你可以得到一个现成的模式或警报在GetBootstrap
更新: 这里是一些知道如何使用引导模式。
这是我如何使用GetBootstrap Modal for asp.net webforms,你可以使用它,如果你想。
下面的代码用于创建一个自定义警报或模式框与正确的asp.net按钮控件,您可以在后端使用。 “你可以在母版页把这个防止重复”
<asp:Panel ID="pnlAlertBox" runat="server" style="position:absolute;top:0;> //You can make is visible or hidden -- you need to customize the style of panel
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">This is customize alertbox</h4>
</div>
<div class="modal-body">
This is the messages...
</div>
<div class="modal-footer">
<asp:Button ID="btnCancel" runat="server" CssClass="btn btn-default" Text="Cancel" />
<asp:Button ID="btnOk" runat="server" CssClass="btn btn-primary" Text="Ok" />
</div>
</div>
</div>
</asp:Panel>
当然你需要包括getboostrap在母版页.js
和.css
文件显示设计。
将此放在头:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet">
将这种形式后:
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
检查HTTP: //sackoveroverflow.com/questions/3831366/display-a-yes-no-alert-box-in-c-sharp-code-behind?rq=1 – Mate 2014-11-05 04:06:57