[英]what should I do at vb.net to display my modal pop up
<asp:Button ID="btnupdate" runat="server" Text="UPDATE" ValidationGroup="check" />
<div id="msgdiv" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<p>
update ok confirm pls login again!!!!!!</p>
</div>
</div>
<script>
var modal = document.getElementById('msgdiv');
var btn = document.getElementById("btnupdate");
var span = document.getElementsByClassName("close")[0];
btn.onclick = function () {
modal.style.display = "block";
}
span.onclick = function () {
modal.style.display = "none";
}
</script>
This code is for the modal pop up message. 该代码用于模式弹出消息。 When I click on the button it should show the modal pop up then when I click the "x" button then it should close.
当我单击按钮时,它应该显示模式弹出窗口,然后当我单击“ x”按钮时,它应该关闭。
The problem is when you click on the update button it shows the modal pop up but immediately goes off. 问题是,当您单击更新按钮时,它会弹出模式对话框,但立即消失。 "its like, it is there but not"
“就像,它在那里,但不在那里”
Should I do anything at back-end code or it can be fixed in front-end code, and how? 我应该在后端代码中执行任何操作,还是可以在前端代码中对其进行修复?如何?
Remove asp:button and make it just input type, runat server: 删除asp:button并使其成为输入类型,运行服务器:
<input ID="btnupdate" runat="server" type="button" value="UPDATE" ValidationGroup="check" />
<div id="msgdiv" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<p>
update ok confirm pls login again!!!!!!</p>
</div>
</div>
<script>
var modal = document.getElementById('msgdiv');
var btn = document.getElementById("btnupdate");
var span = document.getElementsByClassName("close")[0];
btn.onclick = function () {
modal.style.display = "block";
}
span.onclick = function () {
modal.style.display = "none";
}
</script>
The reason that it is disappearing it because the button is posting back and reloading the form it just does it so quickly that you do not see it. 之所以消失,是因为该按钮正在回发并重新加载表单,它是如此之快以至于您看不到它。
ASP.NET Button is always submit
button (input). ASP.NET Button始终是
submit
按钮(输入)。 This server-side tag has an attribute OnClientClick
which is very useful here. 该服务器端标记具有
OnClientClick
属性,在这里非常有用。
<asp:Button ID="btnupdate" runat="server" OnClientClick="return showModal()" Text="UPDATE" ValidationGroup="check" />
<%--Note "return" --%>
...
<script>
function showModal(){
//do what you need to show
return false; //prefent form submission
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.