如何在 asp.net c# 中的 bootstrap 模式弹出窗口中显示来自代码后面的消息
How to show message from code behind in bootstrap's modal popup in asp.net c#
实际上我的意思是当我单击位于模式弹出窗口中的 asp 点网按钮时。
当我单击该按钮时,我想从服务器打印数据是否已正确保存的消息。
当我单击按钮时 bootstrap 的模式弹出窗口消失了,因为回发。
我该怎么做才能从服务器打印消息。
下面是我在HTML.
中的模态pop uo代码
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<asp:Label ID="lblMessage" runat="server" ></asp:Label>
</div>
<div class="modal-footer">
<asp:Button ID="Button2" OnClick="Button2_Click" runat="server" Text="Click Me" />
</div>
</div>
</div>
</div>
c#代码
protected void Button2_Click(object sender, EventArgs e)
{
Label1.Text = "I am called";
}
在点击事件中添加逻辑以在 post 返回后重新打开模式,或者寻找 post 返回服务器的替代方法,例如使用 AJAX .
后面的代码:
protected void Button2_Click(object sender, EventArgs e)
{
lblMessage.Text = "I am called";
ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "showModal();", true);
}
.ASPX:
<head runat="server">
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script type="text/javascript">
function showModal() {
$("#myModal").modal('show');
}
$(function () {
$("#btnShow").click(function () {
showModal();
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="button" id="btnShow" value="Show Modal" />
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<asp:Label ID="lblMessage" runat="server"></asp:Label>
</div>
<div class="modal-footer">
<asp:Button ID="Button2" runat="server" Text="Click Me" OnClick="Button2_Click" />
</div>
</div>
</div>
</div>
</form>
</body>
实际上我的意思是当我单击位于模式弹出窗口中的 asp 点网按钮时。 当我单击该按钮时,我想从服务器打印数据是否已正确保存的消息。
当我单击按钮时 bootstrap 的模式弹出窗口消失了,因为回发。 我该怎么做才能从服务器打印消息。
下面是我在HTML.
中的模态pop uo代码<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<asp:Label ID="lblMessage" runat="server" ></asp:Label>
</div>
<div class="modal-footer">
<asp:Button ID="Button2" OnClick="Button2_Click" runat="server" Text="Click Me" />
</div>
</div>
</div>
</div>
c#代码
protected void Button2_Click(object sender, EventArgs e)
{
Label1.Text = "I am called";
}
在点击事件中添加逻辑以在 post 返回后重新打开模式,或者寻找 post 返回服务器的替代方法,例如使用 AJAX .
后面的代码:
protected void Button2_Click(object sender, EventArgs e)
{
lblMessage.Text = "I am called";
ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "showModal();", true);
}
.ASPX:
<head runat="server">
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script type="text/javascript">
function showModal() {
$("#myModal").modal('show');
}
$(function () {
$("#btnShow").click(function () {
showModal();
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="button" id="btnShow" value="Show Modal" />
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<asp:Label ID="lblMessage" runat="server"></asp:Label>
</div>
<div class="modal-footer">
<asp:Button ID="Button2" runat="server" Text="Click Me" OnClick="Button2_Click" />
</div>
</div>
</div>
</div>
</form>
</body>