[英]How to disable div tag in asp button click
Button click div tag is disabled but after page load again enable. 按钮单击div标签已禁用,但在页面加载后再次启用。 How to stay disable after page load in button click 单击按钮后页面加载后如何保持禁用
<script language="javascript" type="text/javascript">
function toggledisable() {
$(document).ready(function () {
document.getElementById('flip').style.display = "none";
document.getElementById('flip1').style.display = "none";
});
}
</script>
You just changed the display
in client side but the ViewState
of control is not updated. 您只是在客户端更改了display
,但ViewState
没有更新。 You can keep the changed state in hidden field and use those hidden
field no server side to show or hide div
. 您可以将更改后的状态保留在隐藏字段中,并在服务器端不使用这些hidden
字段来显示或隐藏div
。
Also remove document.ready from toggledisable() 还要从toggledisable()中删除document.ready
HTML HTML
<input type="hidden" runat="server" id="hdnflip" />
<input type="hidden" runat="server" id="hdnflip1" />
Javascript Java脚本
function toggledisable() {
document.getElementById('<%= flip.ClientID %>').style.display = "none";
document.getElementById('<%= flip1.ClientID %>').style.display = "none";
document.getElementById('<%= hdnflip.ClientID %>').value = "true";
document.getElementById('<%= hdnflip1.ClientID %>').value = "true";
}
Code behind 后面的代码
flip.Visible = bool.Parse(hdnflip.Value)
flip1.Visible = bool.Parse(hdnflip1.Value)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.